Está en la página 1de 13

Round 1: Q 1. What is the output of the program? # include <stdio.

h> main() { static int a[] = {10, 22, 17, 29, 45}; static int *p[] = {a, a + 2, a + 1, a + 4, a + 3}; int **pp = p; **++pp; printf("%d %d %d", **pp, *pp[3], pp[0][2]); } 17 22 17 17 22 29 29 29 29 17 29 45

Q 2. What is the output of the program? # include <stdio.h> void main() { char str[][5] = {{'h', 'e', 'l', 'l'}, {'w', 'e', 'l', 'l'}}; char str1[15] = "All is "; printf("%s ", strcat(strchr(str1, 'l'), *(str+1))); } lwell llwell ll is well l is well Q 3. What is the output of #include <stdio.h> enum COLORS { violet = 2, indigo, blue = -3, green, yellow, orange = yellow, red }; void main() { enum COLORS col1 = enum COLORS col2 = enum COLORS col3 = printf("%d %d %d", } -1 0 -2 -1 0 3 4 0 -2 -1 6 -2 Q 4. Which statement is correct? the program?

yellow; red; green; col1, col2, col3);

When a pointer is incremented emented by 1 When a pointer is incremented emented by size of integer When a pointer is incremented emented according to the type When a pointer is incremented emented according to the type

by 1, the address contained in the pointer is incr by 1, the address contained in the pointer is incr by of by it 1, the address contained in the pointer is incr pointer 1, the address contained in the pointer is incr is pointing to

Q 5. What is the output of the program? #include <stdio.h> void main() { char p[20] = {"com"}; printf("%s %s", strncat(strset(p, *p), p, strlen(p)), p); } cccccc comcom comcom cccccc comcom comcom com cccccc

Q 6. Consider the following program: main() { char *ptr = %d%t%s ; while(*ptr++!= t ) ; printf(ptr,ptr); } s %s %d%t%s None of the above Q 7. Match the following with reference to the following program code? #include <stdio.h> void main() { int x[3][4] = {{1, 6, 9, 12}, {11, 17, 3, 2}, {20, 23, 4, 5}}; } i) *(x[1] + 2) | x[1][2] 1) 8 ii) *(x[1] + 2) & *(x[2]) 2) 22 iii) ++**x << --x[1][2] 3) 0 iv) (**x ^ x[1][2]) | *(x[2]) 4) 3 i i i i 4, 3, 4, 3, ii ii ii ii 3, 4, 3, 4, iii iii iii iii 1, 1, 2, 2, iv iv iv iv 2 2 1 1

Q 8. What is the output of the following problem: #include <stdio.h> int func (int init) { static int i;

i = init; return (i++); } int main() { int int int for {

i = 2; j = 4; k = 0; (; k < 2; k++) printf( %d , func(i & j)); i = i << 1; j = j << 1;

} return 0; } 00 01 11 12 Q 9. Which of the statements would result in compilation error? Choose the most appropriate? #include <stdio.h> main() { static int array [] = {1, 12, 23, 44, 61}; int *iptr1 = array, *iptr2 = &array[3]; int a, b, c, d; a = iptr1 * 2; // Line 4 b = iptr1 + iptr2; // Line 5 c = iptr2 / 4; // Line 6 iptr1 = iptr2; // Line 7 } Line Line Line Line 4 4 and Line 5 4, Line 5 and Line 6 4, Line 5, Line 6 and Line 7

Q 10. What is the output of the following code? #include <stdio.h> #include <string.h> int (*pf1)(const char *, const char *); char * (*pf2)(char *, const char *); int main() { char buff[10]; pf1 = strcmp; printf("%d ", pf1("hello", "world")); pf2 = strcpy; pf2(buff, "demo"); printf("%s %d", buff, strlen(buff)); } -1 -1 demo 10 demo 4

1 demo 4 Compilation error as function pf1 and pf2 are undefined Q 11. Match the following with reference to the following program code. #include <stdio.h> void main() { int x[3][4] = {{1, 6, 9, 12}, {11, 17, 3, 2}, {20, 23, 4, 5}}; int *n = &x; } i) *(*(x + 1) + 1) 1) 9 ii) *(*x + 1) + 3 2) 13 iii) *(n + 3) + 1 3) 4 iv) ++(*n++) + *n 4) 17 i i i i 3, 2, 4, 4, ii ii ii ii 1, 4, 1, 3, iii iii iii iii 2, 1, 2, 1, iv iv iv iv 4 3 1 2

Q 12. What is the output of the following program: #include<stdio.h> #define REPLACE replace int main() { printf(REPLACE REPLACE%s , REPLACE); return 0; } Compilation error replacereplacereplace ReplaceReplacereplace replaceREPLACEreplace Q 13. typedef union { unsigned int word; unsigned char test[2]; }test; test p = {576}; What value will p.test[0] and p.test[1] have on little-endian architecture? 2,64 64,2 64,1 None of the above Q 14. Which of the following does the stack pointer refer to? the address of address of the the address of the address of the stack in memory last item pushed on the stack the next free stack location the last item popped from the stack

Q 15. Consider the following program: main() { int a=2; if(++a^++a && (a^a) || ++a) printf( %d , a); } The output for the program is: 4 5 6 3 Q 16. What is the output of the program? # include <stdio.h> void main() { int a = 4, b = 8; while(b) { b = b ^ a; printf("%d %d", b << 2 | b, b >> 2 & b); break; } } 60 15 60 15 12 12 0 0

Q 17. What is the output of the program? #include <stdio.h> #define TEST test void main() { char test[] = {"test"}; printf("TEST %s", TEST); } TEST TEST TEST test test test TEST Q 18. What is the output of the program? #include <stdio.h> union ou { union iu { int i; double j; } a[3]; int b[10]; } ouvar; void main() { printf("%d %d %d", sizeof(ouvar), sizeof(ouvar.a),

sizeof(ouvar.a[0].j)); } 40 76 40 40 24 36 24 36 8 8 40 8

Q 19. Consider the following program: main() { char *v[] = { abc , efg , jkl }; char ** p = v; printf( %c , *++p[0]); printf( %c , (*++p)[0]); } The output of the program is: ef ae ce be Q 20. What is the output of the program? static int i = 3; main () { int j = 4; func(j); func(j); } void func (int j) { static int i = 0; if (i == 0) i = j; printf("i = %d", i); } 4,4 3,3 3,4 4,3 Q 21. What is the output of the program? # include <stdio.h> void main() { char str[][3] = {{'h', 'e', 'l'}, {'l', 'o'}, {'w'}}; char str1[20] = "C-language-is-fun"; printf("%s ", strncpy(*str, str1, sizeof(str) - 1)); } C-lan C-l C-langua C-lanuguage-is-fun

Q 22. What is the output of the program? #include <stdio.h> enum DAY { saturday, sunday, monday, tuesday = -1, wednesday, thursday, friday }; void main() { enum DAY d1 = monday; enum DAY d2 = wednesday; printf("%d %d", d1, d2); } 2 2 3 3 3 0 0 4

Q 23. What is the output of the program on a 32 bit OS, if the base address of t he array is 1244992? #include <stdio.h> void main() { int array [3][2][2] = {{{6, 9}, {31, 14}}, {{19, 16}, {17, 88}}, {{91 ,81}, {72, 64}} }; printf("%u ", *array); printf("%u ", **array); printf("%u ", ***array); printf("%u ", array + 1); printf("%u ", **array + 1); printf("%u ", ***array + 1); } 1244992 1244992 1244992 1244992 1245000 1245000 1244992 1244992 6 6 6 6 1245000 1245008 1245000 1245008 1244996 1244996 1244996 1244996 7 31 31 7

Q 24. Which is the output of the following program: #include <stdio.h> #include <string.h> int main() { char a[] = ThisArray ; char *p = APtr ; strcpy(++a, ++p); printf( %s , a+1); return 0;

} PtrsArray PtrArray TptrArray Error Q 25. Which statement is wrong given the following code? int a[] = {5, 7, 9}, *p = a, b; b b b b = = = = *p++; *++p++; *++p; ++*p * *p++;

Q 26. What is the output of the program? #include <stdio.h> int g = 4; void main() { int g = 5; while((g <= 8) && printf(" %d ", g += 2)) { extern int g; printf(" %d ", ++g); if(g > 10) break; else continue; } } 7 7 7 6 8 5 6 7 10 11 9 6 9 7 9 10

Q 27. What is the output of the program? # include <stdio.h> void main() { int mat[4][5] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; printf("%d %d ", *mat[*(mat[3] + 2)], 2[5 + 2[mat] - 3]); } 1 1 0 0 1 0 1 0 Consider union AUnion { int a; float b;}; of the following are the correct with regard to initializing the given uni AUnion a = { 10 }; AUnion a = { 10, 5.5}; AUnion a = { 5.5};

Q 28. Which on: union union union

1,2,3 1,3 2 1,2 Q 29. Consider a two dimensional array int a[10][10]. The address of the 99th elem ent and the value of 99th element can be obtained by *(a *(a *(a *(a + + + + 9 + 9) 9 + 8) 9) + 8 9) + 9 and and and and **(a + 9 + **(a + 9 + *(*(a + 9) *(*(a + 9) 9) 8) + 8) + 9)

Q 30. What does the macro definition DEF in the following code do? #include <stdio.h> #define DEF(any) (char*)(&any) - (char*)((&any) - 1) void main() { int i; char c; double d; printf("%d %d %d", DEF(c), DEF(i), DEF(d)); } Gives the address the variable Gives the size of the variable Gives the address of the variable one element prior to the current one Pointer subtraction Q 31. Consider the following program static int try ( int x1, int x2) { asm mov AX, x1 asm sub AX, x2 return; } main(int argc, char * argv[]) { register int p; register int q; int result; if(argc!=3) printf( error ); p=atoi(argv[1]); q=atoi(argv[2]); result=try(p,q); printf( result = %d , result); } The output of the program if the input is: test 800 300 500 800 junk value 0

Q 32. The output of the following program is main() { unsigned char c; c = 65; bin(c); } void bin(unsigned i) { unsigned n=2; for(n=n<<6; n>0; n=n/2) { if(i & n) printf( 1 ); else printf( 0 ); } } 01000001 00000000 11111111 None of the above Q 33. What is the output of the program? #include <stdio.h> #include <stdarg.h> void func(int cnt, ...) { int i; static int sum = 0; va_list ptr; va_start(ptr, cnt); for(i = 0; i < cnt; i++) sum += va_arg(ptr, int); printf("%d ", sum); va_end(ptr); } void main() { func(3, 0, 1, 2); func(2, 3, 4); func(4, 5, 6, 7, 8); } 3 4 3 4 7 26 8 27 10 36 12 39

Q 34. What is the output of the program, if the base address of the array is 1244896? #include <stdio.h> void main() { struct { float c; union p { char c; char *cp; short s;

} uvar[5]; } svar[6]; printf("%d %d ", &svar[2], &svar[5]); } 1244784 1244944 1244784 1244944 1244976 1245016 1244932 1244992

Q 35. return (x=((((y=2)*z)+((a|b)*(2+s))))); Which of the following expressions use the minimum number of parentheses and is equivalent to the expression above? return return return return (x=(y=2)*z)+(a|b)*(2+s)); x=(y=2)*z+(a|b)*(2+s); x=(y=2)*z+a|b*(2+s); (x=((y=2)*z+(a|b)*(2+s)));

Q 36. What is the output of the program? #include <stdio.h> void main() { int arr[6] = {1}; int *ip = arr; for( ; arr[1]; arr[1]--) printf("%d ", arr[1]); printf("%d %d %d", *(ip + 1), *ip, *(ip + 3)); } 0 0 1 1 1 0 0 0 0 1 0 1 1 1 1 1 0 1 0

Q 37. What does a C program not contain on the stack at run time? Automatic variable Internal Static (Local to function scope) variable Return address of function function parameter Q 38. What would be the correct declaration for an array of pointers to function s which accept an integer and character as arguments and return a float? float (*func)(int, char)[] float (func[])(int , char) float(*func[])(int , char) float(func)(int, char)[] Q 39. What is the output of the following program: #include <stdio.h> #include <string.h> #include<malloc.h> int func(char *p) {

p = (char *)malloc(100 * sizeof(char)); strcpy(p, I am in func; ); printf( %s , p); free(p); return 0; } int main() { char *p = (char *)malloc(100 * sizeof(char)); strcpy(p, I am in main ); func(p); printf( %s , p); return 0; } I am in I am in I am in Runtime func;I am in main func;I am in func main;I am in main error

Q 40. What is the output of the program? #include <stdio.h> void main() { unsigned char C = 32; printf(" %d %d ", C ^= C , !(C & 128) && !(C & 1)); } 0 1 0 0 1 0 0 32

Q 41. What is the output of the program, if the command line input is 3 8? # include <stdio.h> void main(int argc, char *argv[]) { int a, b = 5, c, d, e; for(c = 1; c < argc; c++) { a = atoi(argv[c]); d = a & b; e = (a ^ b) | d; printf("%d %d ", d, e); } } 2 2 1 1 7 1 7 7 13 0 0 13 0 13 2 12

Q 42. What is the output of the following program: #include <stdio.h> int main() { int i = 0; int j = ~0;

unsigned int count = 0; for ( i = 0; i > j; i--) { count++; } printf( %u , count); return 0; } 0 1 2^31-1 2^31 Q 43. What is the output of the following program: #include <stdio.h> int main() { int integer[] = { 0, 1, 2, 3, 4}; int *first = integer; int *second = integer + 1; int diff = second - first; integer[0] += diff; printf( %d, %d , *integer, *(integer + diff)); return 0; } 1,1 1,4 4,1 4,4 Q 44. How do you avoid multiple inclusions of a file in a 'C' program? Using Using Using Using preprocessor directives like #ifndef, #define, #endif preprocessor directives like #ifdef, #undef, #endif #include "filename" conditional statement like if, else if

Q 45. What is output or the error in the program? # include <stdio.h> typedef int CommVault; typedef CommVault CommVaultIndia; void main() { CommVaultIndia val = 234; printf("%d ", val); } Compilation error: typedef cannot be outside a function scope Compilation error: undefined variable val 234 Compilation error: cannot typedef based on another typedef

También podría gustarte