Prog 2 Final Review
A "double" type of data is actually A. a real number that can contain a decimal point (".") B. a long integer with 8 bytes of precision C. a size modifier (x2) for any data type D. used with characters to compensate for the 2-byte Java characters
A
Assuming that the user enters the following string when prompted, ABCDEFGHIJKLM what will the following program print ? char str [80]; printf("Enter the string : "); while((getchar()) != 'H'); scanf ("%s", str ); printf("%s", str); A. IJKLM B. ABCDEFGH C. HIJKLM D. ABCDEFG E. ABCDEFGHIJKLM
A
Assuming the necessary variable declarations have been made, what will the following program print ? char color1[ 10 ]; "blue"; char color2[ 10 ] = "green"; strcpy ( &color1 [4], color2); printf("%s\n", color1); A. bluegreen B. green C. blue D. nothing will be printed due to error E. greenblue
A
Consider this struct declaration WITHOUT a typedef. struct Coordinates { double latitude; double longitude; }; What is now the correct syntax for using this struct? A. struct Coordinates c; B. struct * Coordinates c; C. Coordinates c; D. struct *c = Coordinates;
A
For a text file, we want to calculate how many words there are, and we want to read in one word each time. Which file reading function is most suitable for this task? A. fscanf() B. fgetc() C. fgets() D. sscanf()
A
From where is memory dynamically allocated? A. heap B. Harddrive C. stack D. Static
A
Given this recursive function: void recurse( int n ) { if( n <= 0 ) { return; } else { recurse( n - 2 ); } printf( "%d ", n ); } What is the print out that results from this function call? recurse( 13 ); A. 13 11 9 7 5 3 1 B. 1 3 5 7 9 11 13 C. 13 11 9 7 5 3 1 -1 D. -1 1 3 5 7 9 11 13
A
How are parameters passed by default when it comes to regular variables of primitive data types? A. Pass by value B. Pass by reference C. Pass by name D. Pass by pointer
A
In recursion, what is the term to describe when the new stack frames for these recursive function calls extend beyond the allocated space in the stack? A. Stack overflow B. Stack frame C. Segmentation fault D. Stack exchange
A
In this function, which of the following line numbers is a recursive call. int function( int n, int m){ if( n == 0 || m == 0 ){ return n > m ? n : m; } if( n % 2 ==0){ return function( n - 1, m - 2); } return function( n - 2, m - 2); } A. 10 B. 3 C. 5 D. 1
A
Macros have following properties especially when compared to functions. Find the wrong statement: A. easier to debug B. require processing before compilation C. faster execution D. more readable
A
The assembly stage of compilation produces code in binary format. The code is: A. not ready to execute, it requires linking B. ready to execute if run on the correct platform C. executable depending on the preprocessing of the directives D. executable depending on the assembly language E. in byte code requiring virtual machine interpretation
A
The following sscanf() is used to read in one line of data from a file: 1 char buffer[ 1000 ] = ????; 2 int x, y, z; 3 char w[ 100 ]; 4 sscanf( buffer, "%d,%[^,],%d %d", &x, w, &y, &z ); Which of the following strings can be parsed correctly by this sscanf() above? A. "125,Hello there,12 35" B. "125,Hello there,12,35" C. "125 Hellothere 12 35" D. "125 Hello there 12 35" E. "125,Hellothere,12,35"
A
The printf function needs input parameters. The type of the first parameter: A. Has to be a string B. Depends on the parameters to follow C. Can be char, double, or integer D. Has to be a char E. Any data type used in C
A
What do we use to define a node for a linked list in C? A. struct B. int C. enum D. string.h
A
What does single-step compilation mean? A. All source files are compiled at the same time B. Adding the -o to the gcc statement C. Each source files is compiled separately with its D. own gcc statement E. Adding the -lm to the gcc statement
A
What is a struct? A. A collection of variables of different types B. A collection of variables of different types where only one variable can have a valid value C. An array of integers or doubles D. A set of similar functions
A
What is an abstract data type? A. A model that describes how we will operate on the data B. It is exactly the same as a data structure C. A model for analyzing data D. A model for how many data members are needed
A
What is the result the function call function( 6 ); with this recursive function? int function( int n ) { return n + function( n - 3 ); } A. Stack overflow B. 6 C. 4 D. 3
A
What is the return value of when this function is called with doMagic( 10, 4 )? int doMagic( int x, int y ) { if( x < y ) { return 1; } return 1 + doMagic( x - 1, y ); } A. 8 B. 6 C. 10 D. 7
A
What is the value of *ptr after this code block? int numbers[] = { 35, 57, 78, 66, 41, 12 }; int *ptr = numbers + 5; A. printf( "%p", ptr ); B. printf( "%d", *ptr ); C. printf( "%lf", ptr ); D. printf( "%d", (void *) ptr );
A
What is the value of the file pointer if the the file does not exist? A. NULL B. EOF C. 10 D. "New File"
A
What is wrong with the following program, which is partially written ? int* arr; printf("want an array ? (y/n) : "); a = getchar(); while (!getchar()); while (a = 'y') { arr = (int*)malloc(10000 * sizeof(int)); insert_new_array(arr); // assuming function is present printf(" want another array ? (y/n) : "); a = getchar(); while (!getchar()); }; free(arr); A. Not freeing memory in the same block where it was allocated B. Although different arrays are intented, each time the same array is inserted. C. Arrays cannot be dynamically allocated D. Newly allocated arrays cannot be used- their names are not known E. Should not allocate many arrays, user does not know how much memory we have
A
What will be the value in variable "i" after these instructions execute? int i = 5; switch (i) { case 1: i = 1; break; case 2: i = 2; break; case 3: case 8: case 9: i = 9; break; case 5: i = 5; break; default: i = 4; }; A. 5 B. 4 C. 1 D. 9 E. 2
A
When you compile one source file at a time, what is the resultant file? A. object file B. header file C. linker D. pre-processor macros
A
Which of the following is the correct code to open a file for writing? FILE * fileIn; A. fileIn = fopen( "nameoffile.txt", "w" ); B. fopen( fileIn, "nameofile.txt", "r" ); C. fileIn = fopen( "nameoffile.txt", "r" ); D. fopen( fileIn, "nameofile.txt" );
A
Which of the main function's parameters hold the actual command line arguments? int main( int argc, char *argv[] ) A. argv B. main C. argc D. int
A
Why would you use a indefinite loop, as opposed to a definite loop, to read in all the contents from a file? A. You may not know the amount of content being read in before it is read. B. Indefinite loops cannot be used for reading files. C. Indefinite loops know exactly how many lines are in the input file. D. We do not know if the file exists or not, which is why an indefinite loop must be used for reading content.
A
As we type "make" command on the terminal A. make reads the makefile in the parent directory B. make reads the makefile in the current directory C. None D. make reads the makefile in the predefined environment variable
B
As we type "make" command on the terminal A. make reads the makefile in the parent directory B. make reads the makefile in the current directory C. make reads the makefile in the predefined environment variable D. None
B
Assume fileIn1 is a pointer to an input file opened for reading, fileIn2 is a pointer to another input file opened for reading. The code reads one word from both files and prints them to standard output. 1 char str1[ 20 ], str2[ 20 ]; 2 int x, y; 3 while( ( x = fscanf( fileIn1, "%s", str1 ) ) == 1 && ( y = fscanf( fileIn2, "%s", str2 ) ) == 1 ) 4 { 5 printf( "%s\t%s\n", str1, str2 ); 6 } 7 /* HERE */ How do you check at /* HERE */ if fileIn1 has more words than fileIn2? A. if( x == 0 && y == 1 ) B. if( x > y ) C. if( x != NULL && y == NULL ) D. if( x == y ) E. if( x == NULL && y != NULL )
B
Consider the following struct typedef struct MyStruct { int x; int y; } MyStruct; Which of the following is the correct syntax for accessing a data member of a dynamically allocated struct pointer object named m? A. m.x; B. m->x; C. m[ x ]; D. m-x;
B
Consider this struct declaration WITHOUT a typedef. struct Coordinates { double latitude; double longitude; }; A. struct *c = Coordinates; B. struct Coordinates c; C. struct * Coordinates c; D. Coordinates c;
B
Find which string is the biggerst for comparisons through the strcmp function: char[10] str1 = "bcda"; char[5] str2 = "ca"; char[5] str3 = "cad"; A. str3 and str2 (they are equal) B. str3 C. str1 D. undetermined E. str2
B
Given this recursive function: void recurse( int n ) { if( n <= 0 ) { return; } else { recurse( n - 2 ); } printf( "%d ", n ); } What is the print out that results from this function call? recurse( 13 ); A. 13 11 9 7 5 3 1 -1 B. 1 3 5 7 9 11 13 C. 13 11 9 7 5 3 1 D. -1 1 3 5 7 9 11 13
B
How many stars ("*") will this program print? Int i , j; for (i=1; i<4, i++) { if (i == 3) break; for (j=1; j<4, j++) { if ( j == 3) continue; printf ("* "); }; }; A. 8 B. 4 C. 0 D. 2 E. 6
B
Our program has the following condition at the beginning of the main(). 1 int main( int argc, char *argv[] ) 2 { 3 if( argc == 4 ) 4 { 5 /* do something */ 6 } 7 return 0; 8 } What does this code imply? A. The program is expecting the command line argument "4" B. The program is expecting exactly 4 command line arguments including the name of the executable C. The program is expecting the command line argument 4 D. The program is expecting at least 4 command line arguments including the name of the executable E. The program is expecting exactly 4 command line arguments excluding the name of the executable
B
True or false. A recursive is only allowed to have one base case. A. True B. False
B
What is the correct specifier in fopen() to open a binary file for writing? A. "wr" B. "wb" C. "w" D. "b"
B
What is the output of the following code? #include<stdio.h> int function(); int main(int argc, char* argv[]){ int i; i = function(); printf("%d", i); return 0; } int function(){ int a; a = 250; return 0; } A. No output B. 0 C. Run-time error D. 250
B
What is the value of argc in the main()'s parameters when executing this program with the following command line arguments? ./myprogram alpha 5 beta A. 0 B. 4 C. 5 D. 3
B
What will be the output of the following program? #include <stdio.h> void main() { Int i; if ( (5 > 4) == true) i=10; else i=2; printf ( "#d" , i); } A. 10 B. No output: there is error C. 2 D. 5 E. 1
B
What will the following program segment print? char str [10] = "democracy"; str [4] = '\0'; printf("%s", str); A. demo cracy B. demo C. cracy D. democracy E. demo0cracy
B
Which of the following does an object file NOT contain? A. Placeholders for variables in other files B. C code C. Machine code D. Placeholders for functions in other files
B
Which of the following is a valid and complete function definition? A. void test (int){ printf ( "Hello" ); } B. int test (int x){ return x+1; } C. int test (); void test (x){ printf ( "Hello" ); }
B
Which of the following statements correctly dynamically allocates an array for 10 integers? A. int *m = (int *) malloc( 10 * int ); B. int *m = (int *) malloc( 10 * sizeof( int ) ); C. int *m = (int *) malloc( int ) * 10; D. int *m = (int *) malloc( 10 );
B
If you have a struct to hold information a 2D coordinate, which of the following declarations are correct? A. typedef struct Coordinate { int x; int y; int z; } B. typedef struct Coordinate { double latitude; double longitude; } C. typedef struct Coordinate { double x; double y; } Coordinate; D. typedef struct Coordinate { };
C
In the absence of a exit condition in a recursive function, the following error is given A. Compile-time error B. Both C. Run-time error D. None
C
In the main()'s parameters, how do I access the argument gamma.txt? ./myprogram alpha.txt beta.txt gamma.txt A. argv[ 2 ] B. argv[ 4 ] C. argv[ 3 ] D. argv
C
To write data on screen using fprintf(), what is the FILE * that is used? A. *f B. Correct C. stdout D. stdin E. None
C
What are the contents of array after this code? int array[ 6 ] = { 10, 20, 30, 40, 50, 60 }; int i; for( i = 0; i < 6; i++ ){ if( i % 2 == 1 ){ *( array + i ) = 3; } *array = 100; A. 10, 3, 30, 3, 50, 100 B. 10, 20, 30, 40, 50, 60 C. 100, 3, 30, 3, 50, 3 D. 100, 20, 3, 40, 3, 60 E. 10, 3, 30, 3, 50, 3
C
What does doMagicBeta( 6 ); return? int doMagicBeta( int m ) { if( m < 0 ) return 0; if( m % 2 == 0 ) return 1 + doMagicBeta( m - 2 ); else return 3 + doMagicBeta( m - 1 ); } A. 3 B. 7 C. 4 D. Stack overflow
C
What happens if you pass in more command line arguments that the program is set up to handle? A. Exception. B. Compiler error. C. They are ignored. D. Run time error.
C
What is the output of the following code? int numbers[] = { 35, 57, 78, 66, 41, 12 }; int *ptrA = numbers; int *ptrB = ptrA + 2; int *ptrC = ptrB + 1; printf( "%d, %d, %d\n", *ptrA, *ptrB, *ptrC ); A. 35, 78, 57 B. 66, 35, 41 C. 35, 78, 66 D. 66, 78, 41
C
What is the output of the following code? #include<stdio.h> int test(int); int main(int argc, char* argv[]){ int k=35; k = test(k=test(k=test(k))); printf("k=%d\n", k); return 0; }int test(int k){ k++; return k; } A. k=35 B. k=37 C. k=38 D. k=36
C
What is the output of this code? #define VALUE 10; int main( int argc, char* argv[] ) { int x = VALUE * 2; printf( "%d", x ); return 0; } A. This code results in a run-time error B. 3 C. This code results in a compile-time error. D. 13
C
What makes a function recursive? A. A sequence of steps B. A function that calls functions in the recursion.h header file. C. A function that calls itself to solve a smaller problem with the same algoirthm D. A function that has a nested for loop
C
What will be the output after these instructions execute? char c = "2"; printf ("I will print only %c lines",c); A. I will pring only "2" lines B. I will print only c lines C. I will print only 2 lines; D. I will print only "c" lines E. No output due to Error: integer is used instead of char
C
What will be the output after these instructions execute? float TenPi = 31.415926535; printf ("%1lf \n", Tenpi); A. 3.141593 B. 31.416 C. 31.415927 D. 31.415926535 E. 1.415927
C
What will be the value in variable "i" after these instructions execute? #define SCORE 8 - 4 + 18 int i = 2 * SCORE / 2 ; A. 17 B. 13 C. 21 D. 22 E. 5
C
What will the following program print (assuming necessary #include directives are present ) ? char color1[] = "red"; char color2[] = "blue"; if( strcmp(color1, color2) == 0) printf("These strings are the same.\n"); else if ( strcmp(color1, color2) < 0) printf("red is smaller than blue.\n"); else printf("red is bigger than blue.\n");; A. red is smaller than blue. B. These strings are the same. C. red is bigger than blue. D. true E. 1
C
Which of the following is true for a makefile? A. makefile is used to perform single-step compilation B. makefile can be run directly as a normal executable file - ./makefile C. makefile describes to the make command that how to compile the program D. makefile is a default file provided by gcc, and is not written by the user
C
Why would you use a indefinite loop, as opposed to a definite loop, to read in all the contents from a file? A. Indefinite loops cannot be used for reading files. B. Indefinite loops know exactly how many lines are in the input file. C. You may not know the amount of content being read in before it is read. D. We do not know if the file exists or not, which is why an indefinite loop must be used for reading content.
C
Consider the following struct typedef struct MyStruct { int x; int y; } MyStruct; Assume you have a pointer array that points to an array of MyStructs. Which of the following is the correct syntax for accessing the data member x? A. array->i->x B. array[ x ] C. array[ i ]->x D. array[ i ].x
D
Consider the following struct typedef struct MyStruct { int x; int y; } MyStruct; Which of the following is the correct statement for dynamically allocating an array of MyStructs? Assume there will be 10 elements. A. MyStruct array[ 10 ] = (MyStruct) malloc( sizeof(MyStruct) ); B. MyStruct *arr = (MyStruct *) calloc( sizeof(MyStruct) * 10 ); C. MyStruct *arr = (MyStruct) malloc( sizeof(MyStruct) * 10 ); D. MyStruct *arr = (MyStruct *) malloc( sizeof(MyStruct) * 10 );
D
Consider these statements: int myvar = 57; int *ptr = ?????; What is the correct expression instead of ????? above, to make the variable ptr point to the address of myvar ? A. *myvar B. 57 C. myvar D. &myvar
D
For fopen() in write "w" mode, what happends if the file already exists? A. A new file with a different name will be created. E.g., if "data.txt" exists, a new file named "data(1).txt" will be created. B. fopen() will return an error C. Whatever is there in the file will remain and be appended with the new data. D. The file contents are deleted and overwritten.
D
Find the statement that would stop compilation (no executable code will be generated) due to an error. Assume the following declaration was made: int primes[] = {1, 2, 3, 5, 7,11}; A. primes[2] = 4; B. printf("%d", primes[8] ); C. scanf("%d", primes ); D. scanf("%d", &primes[2]); E. scanf ("%d", primes[3] );
E
How many bytes of memory is allocated with the following instructions? int* arr; arr = (int*) malloc(10 * sizeof(int)); A. 400 B. 80 C. 10 D. 800 E. 40
E
In the following code, the function has a static variable declaration. Find the output. int func1 (int i) { static int s = 5; s = s + i; return s; }; Int main () { int k; k = func1 (1); k = func1 (k); printf ("%d",k ); } ; A. 17 B. 11 C. 5 D. 12 E. 6
E
The main function in a C program A. Can return any data type as long as it is a basic type B. Will return a Boolean if it has input arguments also C. Will not return any value: it is the main program D. Has to return an integer E. Can return an integer
E
You have a program that accepts two additional command line arguments: an output file name and input file name in that order. 1 int main( int argc, char *argv[] ) 2 { 3 if( argc == 3 ) 4 { 5 /* Open Files Here */ 6 } 7 return 0; 8 } Which of the following code correctly opens these files in main() at /* Open Files Here */? A. 1 FILE *f1 = fopen( argv[ 0 ], "w" ); 2 FILE *f2 = fopen( argv[ 1 ], "r" ); B. 1 FILE *f1 = fopen( argv[ 1 ], "w" ); 2 FILE *f2 = fopen( argv[ 2 ], "r" ); C. 1 FILE *f1 = fopen( "argv[ 0 ]", "w" ); 2 FILE *f2 = fopen( "argv[ 1 ]", "r" ); D. 1 FILE *f1 = fopen( argv[ 1 ], "w" ); 2 FILE *f2 = fopen( argv[ 0 ], "r" ); E. 1 FILE *f1 = fopen( "argv[ 2 ]", "w" ); 2 FILE *f2 = fopen( "argv[ 1 ]", "r" );
B
doMagicBeta() is a recursive function that is supposed to print out an array in reverse order. 1 void doMagicBeta( int *array, int number ) 2 { 3 /* Line A */ 4 if( number == 0 ) 5 { 6 /* Line B */ 7 return; 8 /* Line C */ 9 } 10 else 11 { 12 /* Line D */ 13 number = number - 1; 14 doMagicBeta( array, number ); 15 } 16 /* Line E */ 17 } The initial call to this function will pass in an array of integers and the last valid index of the array (size minus one). Where do we put the following printf( "%d\n", array[ number ] ); statement to print out the entire array in reverse order? A. At /* Line D */ B. At /* Line A */ C. At /* Line E */ D. At /* Line B */ E. At /* Line C */
B
what will be printed by the following program? int * ptr1; int ** pptr2 ; int arr[6] = {1, 2, 3, 4, 5, 6}; int i; ptr1 = &arr[2]; pptr2 = &ptr1; i = *ptr1 + *(*pptr2 +1); printf (" %d\n ", i); A. 0x000000000010 B. 7 C. 3 D. 5 E. 0x000000000014
B
Assume that ptr is a pointer to a node in a singly linked list and there are several nodes before and after it. What is the result of this statement? Check all that apply. ptr->next = ptr->next->next; A. Memory leak from ptr's original next node. B. ptr's original next node has been deallocated from the heap C. ptr's original next node is no longer part of the linked list D. No changes to the linked list
C
Assume that the h points to the head of a linked list. Which of the following linked list traversal for loops will correctly get ptr to point at the last item in the linked list? A. Node *ptr; for( ptr = h; ptr->next != NULL; ptr = ptr->next ); B. Node *ptr; for( ptr = h; ptr != NULL; ptr++ ); C. Node *ptr; for( ptr = h; ptr != NULL; ptr->next ) { } D. Node *ptr; for( ptr = h; ptr != NULL; ptr = ptr->next ) { }
C
Assume that you have an external CSV file that has this structure: First-Name,35,Last-Name,5.392 and you want to use fscanf() to parse out the string. What is the format specifier string that will be used to parse this row out? A. "%s,%d,%c,%d" B. "%s,%lf,%s,%lf" C. "%s,%d,%s,%lf" D. "%s,%d,%s,%d"
C
Assume the pointer variable declaration: int *ptr; Which of the following expressions is an example of a dereferenced variable? A. &ptr B. (ptr) C. *ptr D. ptr
C
Given this recursive function: void recurse( int n ){ printf( "%d ", n ); if( n < 4 ) { return; } else { recurse( n - 3 ); } } What is the print out that results from this function call? recurse( 12 ); A. 12 9 6 3 0 B. 15 12 9 6 3 C. 12 9 6 3 D. 10 8 6 4 2
C
Given this recursive function: void recurse( int n ){ printf( "%d ", n ); if( n < 4 ) { return; } else { recurse( n - 3 ); } } What is the print out that results from this function call? recurse( 12 ); A. 10 8 6 4 2 B. 12 9 6 3 0 C. 12 9 6 3 D. 15 12 9 6 3
C
You have a program that will take in three command-line arguments, which includes the name of the executable. You want to check if the third command-line argument is equal to the word READ. Which set of code allows you to check this while staying in bounds of the argv array. A. 1 if( argv[ 3 ] == "READ" ) 2 { 3 printf( "You passed in READ!\n" ); 4 } B. 1 if( argc >= 3 ) 2 { 3 if( strcmp( argv[ 2 ], "READ" ) == 0 ) 4 { 5 printf( "You passed in READ!\n" ); 6 } 7 } C. 1 if( strcmp( argv[ 2 ], "READ" ) == 0 ) 2 { 3 printf( "You passed in READ!\n" ); 4 } D. 1 if( argc >= 3 ) 2 { 3 if( strcmp( argv[ 3 ], "READ" ) == 0 ) 4 { 5 printf( "You passed in READ!\n" ); 6 } 7 } E. 1 if( argc == 3 ) 2 { 3 printf( "You passed in READ!\n" ); 4 }
C
Given this code to read in a file named a.txt, what do we know about the structure of the content in a.txt? Assume that fileIn is an open pointer to a file. 1 char str1[ 20 ], str2[ 20 ]; 2 int num; 3 while( fscanf( fileIn2, "%s %d %s", str1, &num, str2 ) == 3 ) 4 { 5 printf( "%s %d %s\n", str1, num, str2 ); 6 } A. The file contains a repeating pattern of string, int, string, int separated by a space B. The file contains alternating rows of string's and int's C. The file contains alternating rows of int's and strings D. The file contains a repeating pattern of string, int, string separated by a space E. The file contains a repeating pattern of string, int, string separated by a comma
D
Given this macro: #define doSomething( x, y ) x + y * 2 What is the value of result after this code? int result = 2 * doSomething( 5, 7 ); A. 72 B. This code does not compile C. 38 D. 24
D
If you attempt to fopen() a file for writing, but the file does not exist, what happens? A. fopen() is stuck in an infinite loop The program will not compile if the file does not exist B. fopen() returns NULL regardless of whether or not there is write access nor sufficient space C. fopen() results in a run-time error D. fopen() opens a new file with that name and returns a pointer to that file provided there is write access and sufficient space
D
This function is intended to write desired number of stars ("*") on the display. Fine the mistake if there is a mistake: void printStars(int i){ do{ printf("* "); i = i - 1; }while(i>0); } A. Never prints a * B. Prints always one more * than requested D. Does not work correctly for input: 0 C. No mistake E. Prints always one less * than requested
D
This recursive function does not have an explicit base case. void foobar( int n, int m ) { if( n <= m ) { printf( "%d %d\n", n, m ); foobar( n + 1, m ); } } If you had to change this code to include an explicit base case, what would that be? A. if( n == m ) return; B. if( n <= m ) return 0; C. if( n <= m ) return; D. if( n > m ) return;
D
What does doMagicAlpha( 6 ); return? int doMagicAlpha( int m ) { if( m == 0 ) return 0; if( m % 3 == 0 ) return 3 + doMagicAlpha( m - 1 ); else return 1 + doMagicAlpha( m - 1 ); } A. Stack overflow B. 14 C. 0 D. 10
D
What does it mean to dereference a pointer? A. A primitive data type B. A special variable that can be used to represent Boolean values in C C. A variable that holds multiple values D. A variable that holds the memory address of another variable
D
What function should you call after you are done with a file that you have opened? A. fopen() B. feof() C. NULL D. fclose()
D
What is the output of the following program segment? int season = 2; char months [4][3] = {{'d', 'j', 'f' } {'m', 'a', 'y'} {'j', 'u', 'g'} {'s', 'o', 'n'} }; printf("%c", months [season][0]); A. o B. m C. s D. j E. d
D
What is the syntax error in the following lines of code? int i; scanf ("%d, &i); A. There should not be the "&" before "i" B. Should use # instead of % C. Needs a semicolon ( ; ) inside the parentheses D. Needs another double quote (") E. %d and i are not type-compatible
D
What is the value of variable i after executing these statements? int i; i = i+3; A. 1 B. 0 C. 3 D. undetermined E. 4
D
What is wrong with this code for macro? #define doSomething ( x , y ) x + y // this macro adds the two parameters together int m = doSomething( 10, 30 ); A. The macro is missing a semi colon. All #define statements must terminate with a semi colon. B. The #define statements needs a return statement. C. #define statements cannot have parameters--only functions can have parameters. D. The comment in the macro will take anything after the macro call out of compilation. In the assignment statement that follows, it comments out the semi colon
D
What of the following is the correct usage of a typedef type for the following example? typedef int * MyIntegerPointer; A. int x = 5; MyIntegerPointer * p = &x; B. MyIntegerPointer = 5; C. int x = 5; typedef MyIntegerPointer p = &x; D. int x = 5; MyIntegerPointer p = &x;
D
What will be printed after these instructions execute? int i = 3; i = (i=5) ? 4: 2 ; printf ("%d", i); A. 3 B. 0 C. 2 D. 4 E. 5
D
What will f (3) + f (2) * f (1) evaluate to? int f (int n) { static mem = 0; if (n > mem) mem = n; return mem; } A. 7 B. 6 C. 5 D. 12 E. none of these
D
When working with files, what does EOF or eof mean? A. Existence of file is true B. Close file C. File does not exist D. End of file
D
Which one of the following can be concluded for the given code? #define INCASE if #define OTHERWISE else #define WRITE printf #define READ scanf int main(void) { int n; ~~~~~~~~~~ INCASE (READ("%d", &n)) WRITE ("OK\n"); OTHERWISE WRITE ("FAIL!\n"); ~~~~~~~~~~ } A. All macro definitions are causes for compile-time errors. B. The introduced keywords are replacing the reserved words. This is not allowed C. WRITE and READ macro definitions are causes for compile-time errors, but INCASE and OTHERWISE are not. D. there is no problem with the code E. INCASE and OTHERWISE macro definitions are causes for compile-time errors, but WRITE and READ are not.
D
You are recommended to use the "#include<stdio.h>" as the first line. This is because A. To enable inclusion of other files when needed B. To save the operating system from wrong accesses to memory due to programmer faults C. To treat the programming environment as a "studio" for learning purposes D. Being able to use basic input output functions E. To enable macro definitions
D
what would be the value in ptr after executing the following instructions? (assume decimal values) double * ptr = (double *) 1000; ptr++; ptr++; ptr--; A. 1001 B. 999 C. 992 D. 1008 E. 1004
D
