CS201

¡Supera tus tareas y exámenes ahora con Quizwiz!

what are header guards?

#ifndef #endif for example

what is the difference between "a" and 'a'?

"a" is a string literal, a pointer to the character a 'a' is a character (constant), is an integer (the numerical code)

what is another way to write arr[x] ?

*(arr + x)

How scanf recognizes an float?

- (ignoring white space characters) search for a plus sign, or a minus sign - then a series of digits possibly containing a decimal point - lastly a possible exponent: e/E + an optional sign + digits

what are the Three supported arithmetic operations on pointers?

- adding an integer - subtracting an integer - subtract one pointer from another

what is insertion sort?

- builds the sorted list one at a time - inserts a new element into a sorted list

What is bubble sort?

- repeatedly compares two adjacent elements, swaps them if they are in wrong order

What is the return value of scanf?

- the return value is "the number of values successfully read in"

-9/7 what will be the result?

-1, the result of a division is always truncated towards 0

what does the sizeof operator do?

Check how much memory is required to store values of a particular type

source files have what extension?

.c

header files have what extensions?

.h

What does !1 equal?

0

what are the default values of an array?

0

what is the internal form of the float 0.0 ?

0 followed by 4 sets of 8 zeros

what does 0 and 1 mean?

0 means false, 1 means true

what do relational operators produce?

0 or 1

int arr[5]= {1,2,3,4,5} int* p = &arr[2]; int x = p[-2]; printf("%d", x); what is the output?

1

what does !0 equal?

1

int fun() { static int count = 0; count++; return count; } int main() { printf("%d ", fun()); printf("%d ", fun()); return 0; } what will be the output?

1,2

what are two ways to create new datatypes? i.e create a data type answer that is an int

1. #define answer int 2. typedef int answer;

How scanf recognizes an integer?

1. (ignoring white space characters) search for a plus sign, or a minus sign, or a digit 2. then continue reading digits until reaching a non-digit

what are 5 rules for directives?

1. - always start with # 2. - spaces and tabs in the middle irrelevant 3. - end with the first \n, unless continued by \ (backslash) 4. - can appear anywhere, effective immediately afterwards 5. can't end with a ;

Why should we use dynamically allocated storage?

1. Saving memory space 2.supports linked data structures

what are the 3 ways to pass a single dimensional array as an argument in a function? Do they share the same functionality?

1. as a pointer 2. as a sized array 3. as an unsized array Yes. They have the same functionality because each tells the compiler that an integer pointer is going to be received.

what do header files contain?

1. directives - standard library, or user-defined header file such as #include #include "main.h" 2. macro defintions 3. type defintions (like typedef struct) 4. function prototypes 5. shared variables

what is the purpose of functions?

1. divide the program for easier understanding/modifying 2. avoid duplicating code, or re-use

how does gets read characters?

1. gets doesn't skip white space before starting to read a string 2. gets reads until it finds a new line character.. 3. gets discards new line characters instead of storing them and puts a null character it its palce

what are 3 benefits of dividing a program into files?

1. have a clear structure of the program 2. each file can be compiled separately, avoid re-compilation 3. easy re-use of functions in other programs in particular, those dealing with data structures

how can you return a pointer in a function?

1. return a pointer to a global variable 2. return a pointer to a local variable YOU CANNOT RETURN A POINTER TO A VARIABLE THAT HAS BEEN DECLARED INSIDE THE FUNCTION ITSELF

what do malloc, calloc and realloc return?

1. returns a "generic pointer" void * (that is, just a memory address) (pointing to the first byte of the allocated memory unit) 2. returns a null pointer (macro NULL) if allocation fails

What are 2 properties of global variables?

1. static storage duration 2. file scope

Where is the sign bit of an integer or float?

left most bit

Suppose we have: int a[10]; printf("%d", sizeof(a));? what is the output?

40 10*4

int x=006; printf("%d", x); what is the output?

6

what is the output of the following? float x=5.9999 printf("%.2f", x);

6.00 b/c the value of float is rounded to the appropriate number of digits. In this case, ​5.99​ will be rounded to ​6.00​.

int e[] = {1, 2, 3, 4, 5, 6, 7}; what will be the length of this array?

7

what is the size of pointers?

8 bytes.. unsigned long int

int n={8}; printf("%d", n); what is the output?

8.. this is not an error

what are the relational operators?

> , < , >= , <=

what can be stored in a char variable?

A char variable can be initialized with a character literal, which contains one character that is surrounded by a single quotation. .Also, because the char type is the integer type(underneath C stores integer numbers instead of characters), we can initialize or assign a char variable an integer.

what is an array?

A data structure containing a number of data values of the same type. These data values are called elements

what is a string literal?

A sequence of characters enclosed by double quotes

what is the largest signed integer in a 32 bit machine?

A signed 32-bit integer variable has a maximum value of 2^(31)− 1

what is the largest unsigned integer in a 32 bit machine?

A signed 32-bit integer variable has a maximum value of 2^(32)− 1

what is a stream?

A stream is any source of input or any destination for output

int *p = (int []){3,4,5,6}; what does p point to?

p points to the first element of this 4 element array

where do malloc, calloc or realloc obtain memory from?

the heap

What are the four storage classes inC?

Auto, extern, register, static are the four storage classes in 'C'.

What does printf do?

Display the contents of a string, known as the format string

what are 2 disadvantages of using global variables?

Hard to reuse functions in other programs because it depends on the external variable ​Might be difficult to debug the program and identify a function that causes a problem

what is the difference between prefix (++i) and postfix increment (i++)?

In the prefix increment (​++i​), the value of ​i ​is incremented, and the value of the expression is the new value of ​i ​. In the postfix increment (​i++​), the value of ​i ​is incremented, but the value of the expression is the original value of ​i ​.

What does myprogram < text.txt > output.txt mean?

The content of file text.txt goes to stdin in the program, and the output to stdout becomes the content of the output file output.txt

What does %e do?

displays a floating point in exponential format

how are elements in an array stored?

elements are arranged consecutively in memory

What happens if the programmer uses the wrong conversion specification? For example printf("%d", float)

It will print out a random integer

Can a pointer variable point to another variable of a different type? for example: int a; float * p = &a;

NO

Is it legal to nest on comment inside another comment?

NO

consider the following function prototype: int f(int n, int arr[]); can the length of arr be determined by sizeof(arr)/sizeof(int)? why or why not?

NO Because an array sent as a parameter to a function is treated as a pointer, so sizeof will return the pointer's size, instead of the array's.

How do you write a string of text into a file?

Open file and use fprintf

what is the preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

scanf("%d/%d", x, y); suppose the input is _5_/_96 (_ indicates a space) how does scanf read this input?

Scanf skips one white space, matches %d with 5, THEN ATTEMPTS to match the / in the format string with a space in the input.. B/c there isn't a match, scanf puts the space back, so the */*96 characters remain to be read by the next call of scanf

what are the 3 main steps of scanf? (i.e how does it work)

Sequentially, for each conversion specification 1. locate an item of the appropriate type - skip blank space if necessary 2. stop at an inappropriate character (can't belong to the item) 3. put this last character back to the input!

When numbers are printed using printf, are they strings or integer/floats?

Strings

How are addressed typically represented?

The addresses are represented by (hexadecimal, usually) numbers

What does %s or %f or %d do?

The character (s or f or d) specifies how the value is converted from its internal form (binary) to printed form (characters)

Can you assign or manipulate a global variable after declaration? Why or why not?

The compiler only allocates memory to global variables at the compilation stage. If you want to assign or manipulate a value, it can only be done when the variable is initialized The main() function is the entry point for program execution, so only in the main function can you assign values to global variables

int i; for (i=0; i<10;++i); printf("%d", i); what is the output? and why is this the case? what if you used i++?

The for-loop will increment variable i from 0 to 10(not 9) So the printf function will output ​i = 10​. this is the case b/c the variable i will be incremented to 10 and will be checked against i<10, since it fails it stops incrementing... same thing will happen if you use i++

What is the purpose of the header guard (#ifndef ... #endif) in header files?

The header guard prevents type definitions from being repeated, which would cause a compilation error

int a[10] = {0}; int *p= a; what will the expression ++*p=10 do?

This results in an error

What does myprogram < text.txt >> output.txt mean?

This will append any output to the output.txt file, in the case that there is already data in output.txt

when you pass an array name as an argument in a function, how is it treated?

When passed to a function, an array name is always treated as a point

Is there a boolean type in C?

Yes.. _Bool

If you want a variable length array where must you declare the array?

You must declare the array with size N, after you received the value N

char *s= "12345"; printf("%5.2s",s); what wil this print

___12 with 3 spaces in front

what is a memory leak?

a block of memory that is no longer accessible to the program.. example p = malloc(); q= malloc(); p=q;

how many bits does a byte store?

a byte stores 8 bits of information

what is a null character represented by?

a byte whose bits are all zeros. represented as \0

what is the scope of a macro?

a macro defined inside the body of a function isn't local to that function, it remains defined until the end of the file

What is a macro?

a name that represents something else

what kind of pointer can you not return?

a pointer to an automatic local variable. i.e a pointer to variable first declared within the function int *f(void) { int i; .... return &i; }

when is a string terminated?

a string terminates when it sees the null character

what is a local variable?

a variable declared in the body of a function is said to be local to the function

What is static storage duration?

a variable with static storage duration has a permanent storage location, so it retains its value throughout the execution of the program

suppose we have int a[5][10] which element will a[3,4] access?

a[4] the comma operator says expression A (3) will be evaluated first then discarded, then expression b (4) will be evaluated and this is the result of the entire expression

how do you access a file?

accessing via a file pointer type FILE * FILE * fp1, * fp2;

are addresses in bytes back to back in memory?

addresses in memory not necessarily consecutive — machine dependent

what is calloc? void * calloc(X, sizeof(int))

allocates a block of memory and clears it, with 0 in all bits

what is malloc? void *** malloc (# x sizeof(int)) (x=times)

allocates a block of memory but doesn't initialize it (warning: the memory is not cleared, could contain something meaningless)

How does C pick which if to connect an else with?

an else statement belongs to the nearest if statement that hasn't already been paired

what is a compound literal?

an unnamed array that's created on the fly by simply specifying which elements it contains They can be used as array arguments in functions example: (int []){3,4,2}

what can be used as case labels in C?

any constant expression including constant variables.. as well as or, and and other arithmetic operators

how does char *** strcat(char *** s1, const char *** s2) work?

appends the contents of the string s2 to the end of the string s1, then it returns s1

int main(int argc, char* argv[]) What is argc? What is argv?

argv is an array of pointers to the command line arguments which are stored in string form argv[0] points to the name of the program argv[1] until argv[argc-1] point to the remaining command line arguments argc is the number of command line arguments (including the name of the program)

How are string literals stored in memory?

as character arrays.. C will set aside n+1 bytes of memory for the string (if it has n characters).. the +1 byte is for the null character

how are characters treated in C?

as small integers

what is auto

auto is used to store local variables that are within functions

where must function prototypes be placed ?

before the function is called within the program.. it can be before the main function or within the main function before the function call

how can tell you whether an integer is postive or neg?

bit = 0 if pos or 0, bit= 1 if neg

a local variable has what kind of scope?

block scope

How are function parameters and local variables similar?

both have automatic storage duration and local scope

How can you make a[] valid?

by initializing it when you create it. i.e a[]={1,2,3};

what happens if malloc, calloc or realloc is called too often?

can exhaust the heap, causing functions to return a null pointer

what happens if a subscript is out of range of an array? example, a[20] is stored and you call a[22]?

cause undefined behavior

A % 0 ... A / 0 what will happen?

causes undefined behavior

what does fclose do? what does it return?

closes a file. stream must be obtained by fopen or freopen returns 0 if successfully; otherwise error code EOF

how are elements in a 2d array stored in memory?

conceptually, elements are arranged consecutively in memory

How to make a variable constant in C?

const int a

source files consist of what?

definitions of functions and variables

char *s = "Hello, World!"; s+=1; printf(s) what is the result?

ello, World! s is a char pointer pointing to the first character of a string literal ​"Hello, World!"​, and expression s += 1;​ moves pointer s to the second character

what does continue do?

ends the current iteration only

what does #error message do?

error message - when the preprocessor encounters it, prints out the message

how does the comma operator work? i.e expression1 , expression2?

expression 1 is evaluated and its value discarded, then expression 2 is evaluated and its value is the value of the entire expression

What is the conditional expression format?

expression1 ? expression2 : expression 3

extern

extern is for sharing variables within files

if (i==1); what will happen?

extra ";" resulting empty statements

what is the promotion float floating type variables?

float --> doube --> long double

what is the precision for a float and a double?

float =6 double =15

What does fflush(NULL) do?

flushes output streams

What do you need to do before you read or write to a file?

fopen the file

what are one way to free memory?

free function ex. p = malloc(..) free(p) realloc(p, 0) <-- implmentation defined

What is the difference between fscanf() and scanf()?

fscanf() specifies a stream from which to read whereas scanf() can read only from stdin

how can you detect memory errors?

gdb or valgrind

what do the following lines do? ch = getchar() putchar(ch)

getchar() will read a character and store it in ch putchar(ch) will print a single character

What is the controlling expression in this case? What is the constant expression in this case? switch (grade) { case 4: printf("Excellent"); break; case 3: printf("Good"); break; case 2: printf("Average"); break; case 1: printf("Poor"); break; case 0: printf("Failing"); break; default: printf("Illegal grade"); break; }

grade = controlling expression 4, 3,2,1,0 = constant expression

what does fopen do? and what does it return?

its used to open a file. fopen returns a file pointer; if cannot open a file, returns a null pointer

what are the cascaded if statements?

if ( ) { } else if ( ) { } ... else ( ) { }

how do you interpret expression1 ? expression2 : expression 3

if expression 1 then expression 2 else expression 3

how does int strcmp(const char ***s1, const char *** s2) work?

if s1 < s2 returns a value less than 0 if s1 = s2 returns 0 if s1 > s2 returns a value >0

when would the else be executed? if ( ... ) { } else (..) { }

if the expression in the if condition is false or has value 0

how do we create a string that can be modified?

if we need a string that can be modified, set up an character array for example: char date1[8] = "March 8";

int i; for (i=0; i<10;); printf("%d", i++); what will result?

in this case, it will continue forever b/c we don't have an update step

for (int i=0; i<10;) printf("%d", i++); what will result?

in this case, it will print 0 through 9

how to print %

include %%

how to print "

include \"

How to print \

include \\

which one is valid? (int *) s; or int ( *t );

int (*t)

what is the difference between int *const a and const int * a?

int * const a → a is a constant pointer. You can change the value at the location pointed by pointer a, but you can not change a to point to another location. const int * a is a pointer to a constant. You can change a to point to other variables. But you cannot change the value pointed by a.

what is the promotion of int types?

int --> unsigned int--> long int --> unsigned long int

the controlling expression used in switch must be what type of variable?

int only.. but characters can be used since they are treated as integers in C

What are examples of lvalues?

int x, int *p;

can struct do comparsion == or equality =?

it can do = but not ==

what is #?

it converts a macro argument into a string literal it can only be used in the replacement list of a parametrized macro

What does & mean before a variable?

it means the "memory unit address" of the variable

what is puts(str)?

it prints out the string str then prints out an \n

ch = "We discuss strings today."[0]; what will printf("%c") output?

it will print out W

What happens if you try to use an uninitalized variable?

it will result in random behavior

What characters are valid in identifiers?

letters, numbers and underscore only

what is a union?

like a structure, but the compiler allocates only enough memory for the largest of the members

What does the m and p stand for in %m.ps

m= minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. p: the maximum number of characters to be printed. By default all characters are printed until the ending null character is encountered.

what are the 3 functions that can allocate memory?

malloc, calloc and realloc

what is a null character used for?

marks the end of the string

what variable does % operator require? and what are the consequences if it doesn't receive them?

must be int, it won't compile if either value isn't an int

What can an identifier start with? (i.e name of a variable, function, etc)

must start with a letter or underscore

Can there be duplicate case labels in switch?

no

Can you apply * to an int variable?

no

Is i*2 an l value?

no

Is this valid a[];?

no

are pointers automatically initalized?

no

does strlen include the null character in the total length?

no

does switch need a default value?

no

does the compiler check if the string is full when using gets or scanf?

no

does the compiler check if you included a null character for the string?

no

struct { char name[NAME_LEN + 1]; int marks; int grade; } student1 struct { char name[NAME_LEN + 1]; int marks; int grade; } student2; are student1 and student2 of the same structure?

no

Are "abc" and "abc\0" the same string literal?

no b/c the second one will contain 2 null characters and the first one will only contain one null character

can scanf read a full line ?

no because scanf doesn't read in white spaces or tabs

does scanf skip white space characters before reading a character?

no,

if you have char *s; can you read anything in to it?

no, b/c it doesn't point to any valid memory address

do you need to put a & operator in front of a string variable in scanf? how does scanf read strings? for example: scanf("%s", str)

no, b/c str is treated as a pointer when passed to a function when scanf is called, it skips white spaces, then reads characters and stores them in str until it encounters a white space character. Scanf will then store a null character at the end of the string.

int sum_array2(int a[n], int n); is this valid? why or why not?

no, because we don't know the value of n when it's called

does the order of the case labels matter?

no, i.e the default case doesn't need to come last

can you assign a value to variable of a narrower type? ie. char c= 10000;

no, it will create a meaningless result or create a warning

Can you directly copy one string into another?

no, need to use strcpy

is # or ## recognized by the compiler?

no, they are executed during preprocessing

Given int a[10]; int b=7; a=&b; is this valid?

no, you cannot change what a points to, if a is an array

is this valid? char *a= "a"; printf("%c", a)

no, you have to change %c to %s

is the null character counted towards the length of the string?

not counted into the length of the string

the constant expression used in switch must be of what data type?

only int, including char b/c they are converted to integers

When will printf skip white spaces?

only when its looking for an actual variable

what does the .p in printf("%.ps", str) do?

p is the number of characters to display.. this will print out the first p number of characters only

Given: int a[10], *p; p=&a[2]; p+=6; what is the result?

p now points to a[8]

What is the main difference between function parameters and local variables?

parameters are initialized automatically when a function is called (by being assigned the value of the corresponding argument)

In C, how are arguments passed?

passed by value, when a function is called, each argument is evaluated and its value is copied into the corresponding parameter

What is a conversion specification?

placeholder representing a value to be filled in during printing

what happens if the first and third expression in a for loop are ommitted?

pretty much the same as a while loop

what happens if you use scanf("%d", &x) and x was declared a float?

print out a random value

Printf("%d", i , j ) What will happen?

printf prints the value of i but doesn't show the value of j

Printf("%d %d", i) What will happen?

printf will print the value of i correctly, then print a second random integer value

char s[]= "Hey"; printf("%s", str); how does printf work in this case? What happens if a null character is missing?

printf writes characters in the string one by one until it encounters a null character. if the null character is missing, it will continue printing past the end of the string until it eventually finds a null character somewhere in memory

When will a float variable round up when printing?

printf("%.Af", number) where A is the number of places after the decimal.. if the number of decimal places in the float variable is > the number of decimals allowed (i.e value of A) then C will round up if the number of decimal places in the float variable is < the number of decimals allowed , it won't round up

for ex: #define PRINT_INT(n) printf(#n " = %d\n", n) PRINT_INT(a/b) what will this produce?

printf("a/b = %d\n", a/b);

what letter do you use to read/write a short int?

put a h in front of the typical letter.. so hd for short int hu for short unsigned int ho for short integer in base 8 and so on

what letter do you use to read/write a long variable?

put a l in front of the typical letter

what is register

register is to store variables in CPU registers for quicker access

what are white space characters

regular spaces, \n (i.e return key) and \t (tab)

What are lvalues?

represents an object stored in computer memory, not a constant or a result of a computation

what is realloc?

resizes a previously allocated block of memory

what is function prototype?

return-type function-name ( parameters );

what is the return value getchar?

returns the character it reads,, in integer form

scanf("%d/%d", x, y); suppose the input is _5/_96 (_ indicates a space) how does scanf read this input?

scanf skips the first space while looking for an integer, matches %d with 5, matches / with /, skips a white space while looking for another integer and matches %d with 96

how can you force scanf to skip white spaces before reading a character?

scanf(" %c", ch); put a space in its format string

what is a string?

series/sequence of characters

what are parameterized macros?

serve as simple functions generic (no data type):

by default are integers signed or unsigned?

signed

is char signed or unsigned by default?

signedness of plain char is implementation defined.

How do you assign a char variable?

single quotes A = 'a', not double quotes

what is automatic storage duration?

storage for a local variable "automatically" allocated when the enclosing function is called and deallocated when the function returns

what are Aggregate variables ?

store a collection of values such as arrays or structures

how does strcpy(char ***s1, char *** s2) work? (note to callie: i wrote *** instead of one b/c it kept bolding it)

strcpy copies the string pointer to by s2 into the array pointed to by s1... up to and including the first null character in s2

struct student { char name[NAME_LEN + 1]; int marks; int grade; } student1; what is the struct tag? and how can it be used?

student is struct tag, it is used to identify a particular kind of struct you can then write struct student s1, s2; this will create 2 student structs s1 and s2

What does the #include directive do?

tells the preprocessor to open a particular file and include its contents as part of the file being compiled

what kind of files can be used?

text or binary

int a[10] = {0}; int *p= a; what will the expression *++p=10 do?

the ++p will move p to point to a[1] then it will change a[1] to equal 10

what is the input to the preprocessor?

the C program, possibly containing directives

what is dynamic storage allocation?

the ability to allocate storage during program execution

int sum_array1(int a[10]); what kind of array can be used in this function?

the actual array length must be ≥ 10,but only the first 10 elements used

What is the address of a variable?

the address of the first byte is the address of the variable

what does char *p= "abc" mean?

the assignment doesn't copy the characters in "abc", it merely makes p point to the first character of the string.

what is i<< j mean?

the bits of i shifted left by j places, adding 0's at the right equivalent to i *= 2^j

what is i >> j mean?

the bits of i shifted right by j places, adding 0's at the left (equivalent to i /= 2^j)

char s[] = "Hello World"; s+=1; printf(s); what will the result be?

the code has an error b/c s is an array, not a pointer, and you cannot increment an array variable.

what is a structure data type?

the elements of a structure aren't required to have the same data type

What is the difference between the two? char student[][24] = { "Rupehra", "Kevin Joseph", "Matthew", "Boyuan", "Dylan", "Laura"} char *student[] = { "Rupehra", "Kevin Joseph", "Matthew", "Boyuan", "Dylan", "Laura"}

the first is a 2d array, student[1] points to "Kevin Joseph" can be changed! the second is a array of character pointers.. student[1] points to "Kevin Joseph", but this cannot be changed

for (int i =0; i<10 ; ); printf("%d\n", i++); what will result?

the identifier ​i ​in ​printf​ function is undeclared. There will be a compile error if you run it.

if the second expression is omitted in a for loop what happens?

the loop will never terminate

what is the memory size of a union?

the memory occupied by a union will be large enough to hold the largest member of the union

what is one way pointers an arrays are related?

the name of an array can be used as a pointer to the first element in the array int a[10]; *a=7; this will store 7 in the first element in array a

What does #define do?

the preprocessor expands the macro, replacing it by its defined value

#define MK_ID(n) i##n work int MK_ID(1) what happens in this code?

the preprocessor first replaces the parameter n with 1 then joins i and 1 to make a single token i1

what happens when one pointer is subtracted from another?

the result is the distance between the pointers

what is the storage duration of a variable?

the storage duration of a variable is the portion of program execution during which storage for the variable exists

how are & and * related?

they are inverses so * & and & * cancel eachother out

what will printf("%.5d", X) do?

this adds extra zeros to the beginning of the number X so that the number of digits display equals 5

what is argv[argc]?

this is a null pointer, that points to nothing

Given int a[10]; what does a+i mean?

this is the same as &a[i]

what does ae3 mean?

this means a times 10^3

what is block scope?

this means it is visible from its point of declaration to the end of the function

what is file scope?

this means the variable is visible from its point of declaration to the end of the enclosing file. It can be accessed/modified by all functions that follow its declaration

what does const int *p mean?

this means you can't change the integer that p points to

what does int * const p mean?

this means you can't change what p is pointing to,

what will printf("%8.2f", X) do?

this will add spaces to the left side of X such that the min number of characters used is 8... the .2 means we will show the value of X with only 2 points after the decimal place

what happens if you say try to compile if (x=0) { ... }

this will assign 0 to x and produce 0 since the result is 0

What is the value for variable i: int array[10]; int i = array[5];

this will output a random number... arrays are only initalized to zero if you include {}

what will printf("%10d", X) do?

this will print out enough spaces on the left hand side of X such that the total number of characters is at least 10 (including the X value)

what will printf("%-10d", X) do?

this will print out enough spaces on the right hand side of X such that the total number of characters is at least 10 (including the X value)

What does break do? switch (grade) { case 4: printf("Excellent"); break; case 3: printf("Good"); break; case 2: printf("Average"); break; case 1: printf("Poor"); break; case 0: printf("Failing"); break; default: printf("Illegal grade"); break; }

to get out of switch (otherwise all following statements executed)

each byte has a unique address ? true or false

true

does each source file have a corresponding header file? true or false

true, except for the main.c

how is typedef used?

typedef struct { char name[NAME_LEN + 1]; int marks; int grade; } student; now student can be used to declared variables of this type w/o having to include struct

what letter is used to read/write: unsigned integer in base 10= unsigned integer in base 8= unsigned integer in base 16=

u o x

what happens if you try to access the contents of a pointer variable that hasn't been initialized?

undefined behavior, could crash, could print a garbage value

what happens when a block of memory is freed twice?

undefined behavior, most likely result in a program fault

what happens if you try to access or modify a deallocated memory block?

undefined behavior..

how can you read an entire lline of input?

use gets

How do you open a file for binary input-output?

use the b flag

how to invoke make?

use the command make target, where target is one of the targets listed in the makefile.. if no target is specified when make is invoked, it will build the target of the first rule

How can you make a variable have static storage duration?

uses the key word static

What are external/global variables?

variables that are declared outside of the body of any function

what are pointer variables?

variables the store the addresses of other variables

int x; float w=4.0; x=w what happens to w?

w is converted to an int.

int sum_array2(int a[], int n) how long can a be?

when called, the length argument must be ≤ the actual array length

how does scanf read strings?

when scanf is called, it skips white space, then reads characters and stores them until it encounters a white space character. scanf always stores a null character at the end of the string

when does strcpy STOP copying str2 into str1 ?

when str2 reaches its null character,

what is the dangling else problem?

when there are nested if statements, and we aren't sure which if statement, the else statement belongs to

when is pointer subtraction valid? i.e subtracting two pointers

when they both point to elements of a shared array

int a=5; printf("%d", *a); what is the output?

wil not compile

-9 % 7

will be -2, it copies the sign of the left operand

what is another way to declare a struct variable?

with typedef

how does sprintf(str1, "%d", ms_number) work?

writes the integer value of ms_number into str1 so the integer is converted to a string DOES NOT PRINT STR1 OUT if the third argument isn't included and the second argument only contains "somewords", then sprintf just puts "somewords" into the str1 string

difference between ++x and x++?

x++: Postfix increment operator means the expression is evaluated first using the original value of the variable and then the variable is incremented(increased). ++x Prefix increment operator means the variable is incremented first and then the expression is evaluated using the new value of the variable.

Can x++ or ++x compile if x is a float?

yes

Does the preprocessor make changes to our source code?

yes

Is this valid? switch (grade) { case 4: case 3: case 2: case 1: printf("Passing"); break; case 0: printf("Failing"); break; default: printf("Illegal grade"); break; }

yes

do characters have both signed and unsigned types?

yes

do you have to include a null character for a strng?

yes

does unsigned short int and unsigned short mean the same?

yes

is a[2] an l value?

yes

is it valid to index an array with a negative value?

yes

struct { char name[NAME_LEN + 1]; int marks; int grade; } student1, student2; are student1 and student2 of the same structure?

yes

is it valid to omit the third expression in a for loop?

yes but the loop body is now responsible for ensuring that the value of the second expression eventually becomes false

are static and global variables initialized by default?

yes to 0

char * t = "March 8"; can you access the string using t[3]?

yes, but you can't change the string this way

what are 2 advantages of global variables?

​Reusing a variable among many functions​ and few functions reusing many common variables

what is a makefile?

• A file containing the information for building the program

How are array arguments passed? by value or by reference?

• Pass-by-value: the value is the address of the array • Consequently, the values of the array elements can be changed

what does & and * mean ? (pointer operators)

•& — getting the address of a variable • * — getting the value stored in an address (the object pointed to by a pointer)


Conjuntos de estudio relacionados

Chapter 14 - Assessing Skin, Hair, and Nails

View Set

Chapter 7: Periodic Properties of Elements

View Set

2.5 Function of Financial Intermediaries: Indirect Finance

View Set

Chapter 7 Drug Information References

View Set