My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
|
Brain bench questions
Posted Date: 23 Mar 2008 Resource Type: Articles/Knowledge Sharing Category: Placement Papers
|
Posted By: Logeshwaran Member Level: Gold Rating: Points: 5
|
|
|
|
1.Sample Code int x = 011 | 0x10; What value will x contain in the sample code above? Choice 1 3 Choice 2 13 Choice 3 19 Choice 4 25 Choice 5 27 2.Source Files /* print.c */ #include Void print() { printf( "World\n" ); }
/* main.c */ #include static void print() { printf( "Hello\n" ); } int main() { print(); return 0; } Referring to the program given by the 2 source files defined in the code above, what will happen when you try to build and run the program? Choice 1 It will print: Hello World Choice 2 It will not compile. Choice 3 It will not link. Choice 4 It will print Hello Choice 5 It will print World
3.Code int x = 3;
if( x == 2 ); x = 0; if( x == 3 ) x++; else x += 2; What value will x contain when the sample code above is executed? Choice 1 1 Choice 2 2 Choice 3 3 Choice 4 4 Choice 5 5 4. Code void getFileLength( char *s ) { FILE *f; if( f = fopen( s, "r" ) ) { fseek( f, SEEK_END, 0 ); printf( "%d\n", ????? ); fclose( f ); } } Which of the following could replace the ????? in the code above to cause the function to print the length of the file when a valid file name is passed to it? Choice 1 filelen( f ) Choice 2 position( f ) Choice 3 ftell( f ) Choice 4 tell( f ) Choice 5 fposition( f ) Code void getFileLength( char *s ) { FILE *f; if( f = fopen( s, "r" ) ) { fseek( f, SEEK_END, 0 ); printf( "%d\n", ????? ); fclose( f ); } } Which of the following could replace the ????? in the code above to cause the function to print the length of the file when a valid file name is passed to it? Choice 1 filelen( f ) Choice 2 position( f ) Choice 3 ftell( f ) Choice 4 tell( f ) Choice 5 fposition( f ) 5. Which of the following is valid for opening a read-only ASCII file? Choice 1 fopen (filenm, "read"); Choice 2 fileOpen (filenm, "ra"); Choice 3 fileOpen (filenm, "r"); Choice 4 fopen (filenm, "r"); Choice 5 fileOpen (filenm, "read"); 6. What is the maximum value of a signed data type that is 8 bits in size? Choice 1 2 to the power of 7 Choice 2 (2 to the power of 8) minus 1 Choice 3 2 to the power of 8 Choice 4 (2 to the power of 7) minus 1 Choice 5 2 to the power of 16 7. Code int x = 10; int *xPtr0, *xPtr1, *xPtr2, *xPtr3;
xPtr0 = &x; xPtr1 = xPtr0; xPtr2 = xPtr1; xPtr3 = xPtr2; Referring to the sample code above, which of the following print statements would correctly print out the value of x? Choice 1 printf("xPtr0=%d\n", xPtr3); Choice 2 printf("xPtr0=%d\n", ***xPtr3); Choice 3 printf("xPtr0=%d\n", ****xPtr3); Choice 4 printf("xPtr0=%d\n", *xPtr3); Choice 5 printf("xPtr0=%d\n", **xPtr3); 8. Code f = fopen( filename, "r" ); Referring to the code above, what is the proper definition for the variable f? Choice 1 int f; Choice 2 struct FILE f; Choice 3 FILE f; Choice 4 char *f; Choice 5 FILE *f; 9. Code char ptr1[] = "Hello World"; char *ptr2 = malloc( 5 );
ptr2 = ptr1; What is wrong with the above code (assuming the call to malloc does not fail)? Choice 1 It will not compile. Choice 2 There will be a memory leak. Choice 3 Not enough space is allocated by the malloc. Choice 4 There will be a segmentation fault. Choice 5 There will be a memory overwrite. 10. Which of the following will give a hint to the compiler that might better optimize a frequently used local variable? Choice 1 Declaring it as static Choice 2 Declaring it as volatile Choice 3 Declaring it as extern Choice 4 Declaring it as register Choice 5 Declaring it as auto 11. Code int x = 5; int y = 2; char op = '*';
switch (op) { default : x += 1; case '+' : x += y; case '-' : x -= y; } After the sample code above has been executed, what value will the variable "x" contain? Choice 1 4 Choice 2 5 Choice 3 6 Choice 4 7 Choice 5 8 12. Which of the following characters will cause a printer to perform a form feed? Choice 1 '\b' Choice 2 '\f' Choice 3 '\n' Choice 4 '\r' Choice 5 '\s' 13. Code int x = 0;
for ( ; ; ) { if (x++ == 4) break; continue; }
printf("x=%d\n", x); What will be printed when the sample code above is executed? Choice 1 x=0 Choice 2 x=1 Choice 3 x=4 Choice 4 x=5 Choice 5 x=6 14. Sample Code long factorial (long x) { ???? return x * factorial(x - 1); } What would you replace the ???? with to make the function shown above return the correct answer? Choice 1 if (x >= 2) return 2; Choice 2 if (x == 0) return 1; Choice 3 return 1; Choice 4 if (x <= 1) return 1; Choice 5 if (x == 0) return 0; 15. What is a variable DECLARATION (as opposed to definition)? Choice 1 The assignment of storage space to a variable whose properties have been specified external to the current file scope. Choice 2 The assignment of properties to a variable Choice 3 The assignment of properties and storage space to a variable Choice 4 The assignment of properties and identification to a variable Choice 5 The assignment of storage space to a variable 16. Sample Code const int n = 5;
int i, array[ n ];
for (i = 0; i < n; i++) { array[ i ] = i; } What will happen when the sample code fragment above is executed? Choice 1 The code will compile, but not link. Choice 2 The code may have problems at run time. Choice 3 The code will not compile. Choice 4 The code will compile with warnings. Choice 5 The array will be initialized with the numbers 0 through 4. 17. Code char *x; x = "DATA"; Is the above code valid? Choice 1 No. It would assign the string "DATA" to an unallocated space in memory. Choice 2 Yes. Upon initialization, the string "DATA" will be stored in a special pointer memory address space. Choice 3 No. This syntax is not allowed. Choice 4 Yes. The pointer x will point to the memory location created for the constant "DATA". Choice 5 Yes. A new memory space will be allocated to hold the string "DATA". 18. Code int i; int *ptr;
for (i = 1; i<5; i++) { ptr = (int *) calloc(i, sizeof(int)); } How will the sample code above behave when executed? Choice 1 It will result in a memory over-write. Choice 2 It will result in a run-time error since the pointer "ptr" is undefined. Choice 3 It will allocate 4 pointers of different sizes for later use. Choice 4 It will allocate 3 pointers of different sizes for later use. Choice 5 It will result in a memory leak. 19. Code int i,j; int ctr = 0; int myArray[4][4];
for (i=0; i<4; i++) for (j=0; j<4; j++) { myArray[i][j] = ctr; ++ctr; } What is the value of myArray[2][3]; in the sample code above? Choice 1 6 Choice 2 7 Choice 3 9 Choice 4 11 Choice 5 14 20. How is time defined by the POSIX standard? Choice 1 Time = number of seconds since GMT, 1/1/1900 Choice 2 Time = number of seconds since GMT, 1/1/1940 Choice 3 Time = number of seconds since GMT, 1/1/1950 Choice 4 Time = number of seconds since GMT, 1/1/1960 Choice 5 Time = number of seconds since GMT, 1/1/1970 21. US Coins penny = one nickel = five dime = ten quarter = twenty-five How would enum be used to define the values of the American coins listed above? Choice 1 enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25}); Choice 2 enum coin (penny=1, nickel=5, dime=10, quarter=25); Choice 3 enum coin {penny=1, nickel=5, dime=10, quarter=25}; Choice 4 enum coin {penny, nickel, dime, quarter} (1, 5, 10, 25); Choice 5 enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)}; 22. What header file is required for standard C library mathematical functions? Choice 1 stdlib.h Choice 2 math.h Choice 3 mathematical.h Choice 4 stdmath.h Choice 5 mathfunc.h 23. Code #include
int i;
void increment( int i ) { i++; }
int main() { for( i = 0; i < 10; increment( i ) ) { } printf("i=%d\n", i); return 0; } What will happen when the program above is compiled and executed? Choice 1 It will not compile. Choice 2 It print out: i=9 Choice 3 It print out: i=10 Choice 4 It print out: i=11 Choice 5 It will loop indefinitely 24. Code int *ptr = malloc(5 * sizeof(int));
realloc(ptr, 5 * sizeof(int));
for (i=0; i< 10; i++) { ptr[i] = 0; } Assuming realloc succeeds, what effect will the above sample code have on the rest of the program? Choice 1 The pointer "ptr" will contain an array of 10 that is initialized to 0 with no issues. Choice 2 This will result in a memory overwrite but no memory leak. Choice 3 This will result in a memory leak but no memory overwrite. Choice 4 This will result in both a memory leak and memory overwrite. Choice 5 All but the last in the array of 10 integers will be initialized to 0. 25. Sample Code void output (int x) { if (x != 0) { output(x / 16); putchar("0123456789ABCDEF"[x % 16]); } else putchar('\n'); } What will be output if the above function is called with x = 1234? Choice 1 1234 Choice 2 2322 Choice 3 4321 Choice 4 4D2 Choice 5 It will not compile. 26. Code #define MAX_NUM 15 Referring to the sample above, what is MAX_NUM? Choice 1 MAX_NUM is a precompiler constant. Choice 2 MAX_NUM is a preprocessor macro. Choice 3 MAX_NUM is an integer constant. Choice 4 MAX_NUM is an integer variable. Choice 5 MAX_NUM is a linker constant. 27. Which of the following will turn off buffering for stdout? Choice 1 setbuf( stdout, _IONBF ); Choice 2 setvbuf( stdout, NULL ); Choice 3 setvbuf( stdout, _IONBF ); Choice 4 setbuf( stdout, FALSE ); Choice 5 setbuf( stdout, NULL ); 28. Code char buf[5] = "a";
const char *ptr = buf; Given the above, which of the following statements is legal? Choice 1 ptr = buf; Choice 2 *ptr = "a"; Choice 3 *ptr = buf; Choice 4 ptr = 'a'; Choice 5 None of the above 29. Code int z = 0; int y;
for( y=1; y++ < 8; )
z += y;
printf("z=%d\n", z); What will be printed when the sample code above is executed? Choice 1 z=8 Choice 2 z=9 Choice 3 z=27 Choice 4 z=28 Choice 5 z=35 30. Code int counter = 0; int aMatrix[5][5]; register int *aPtr; int i, j;
for (i=0; i<5; i++) for (j=0; j<5; j++) aMatrix[i][j] = counter++;
aPtr = &aMatrix[1][1];
printf("%d\n", aPtr[2]); Referring to the sample code above, what will be the value of "aPtr[2]", after execution? Choice 1 5 Choice 2 6 Choice 3 7 Choice 4 8 Choice 5 9 31. What is a variable DEFINITION (as opposed to a declaration)? Choice 1 The identification of a variable that resides elsewhere in the program Choice 2 The assignment of storage space to a variable Choice 3 The assignment of properties to a variable Choice 4 The assignment of storage space to a variable whose properties have been specified external to the current file scope. Choice 5 The assignment of properties and storage space to a variable 32. Statements A) A definition allocates storage for the variable.
B) A declaration allocates storage for the variable.
C) A definition can occur muliple times
D) A declaration can occur multiple times Regarding the difference between a declaration and a definition of a variable, which of the above stataments are true? Choice 1 A and C only Choice 2 A and D only Choice 3 B and C only Choice 4 B and D only Choice 5 none of the above 33. Which of the following statements allocates enough space to hold an array of 10 integers which are initialized to 0? Choice 1 int *ptr = (int *) alloc(10*sizeof(int)); Choice 2 int *ptr = (int *) calloc(10*sizeof(int)); Choice 3 int *ptr = (int *) malloc(10, sizeof(int)); Choice 4 int *ptr = (int *) calloc(10, sizeof(int)); Choice 5 int *ptr = (int *) malloc(10*sizeof(int)); 34. Code char buf1[100] = "Hello"; char buf2[100] = "World";
char *strptr1 = buf1 + 2; char *strptr2 = buf2 + 3;
strcpy( strptr1, buf2 ); strcpy( strptr2, buf1 );
printf( "%s\n",buf1 ); printf( "%s\n",buf2 ); Given the sample code above, which of the following string values will be printed when the code is executed? Choice 1 HelWoHello WoHello Choice 2 HeWorHello WorHello Choice 3 HeWorld WorHeWorld Choice 4 HelWorld WoHelWorld Choice 5 HeWorld WorHello 35. Code char helloWorld[12]; char hello[6] = "Hello"; char world[7] = "-World"; Using the definitions above, how can the string "Hello-World" be placed into helloWorld? Choice 1 That would not be legal because helloWorld is not declared large enough to hold the string "Hello-World" Choice 2 helloWorld = hello + world; Choice 3 strcpy( helloWorld, hello + world ); Choice 4 strcpy( helloWorld, hello ); strcat( helloWorld, world ); Choice 5 strcat( hello, world ); strcpy( helloWorld, hello ); 36. Source File #include
int main() { print( x++ ); }
int x = 5;
void print( int x ) { printf( "%d\n", --x ); } Referring to the source code file shown above, what will be printed when the code is executed? Choice 1 4 Choice 2 5 Choice 3 6 Choice 4 That file will not compile. Choice 5 That file will compile, but not link 37. What file I/O function is used to report the number of bytes from the beginning of the file to the file position indicator? Choice 1 freport Choice 2 fposind Choice 3 fseek Choice 4 ftell Choice 5 Fcount 38. Code char y = 'A'; char *ptr_y; Referring to the sample code above, how would ptr_y be assigned to point to y? Choice 1 *ptr_y = &y; Choice 2 *ptr_y = y; Choice 3 (char *) *ptr_y = y; Choice 4 ptr_y = (char *)y; Choice 5 ptr_y = &y;
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
Watch TV Channels
|