General 02
Instructions:1. Please ignore any case-sensitive errors and un-included libraries.2. You may use the back of this question paper for any rough work.
Q1.main(){ int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1;}a. Runtime error.b. Runtime error. Access violation.c. Compile error. Illegal syntaxd. None of the above Ans: d, printf( ) prints address/garbage of i, scanf() dont hav & sign, so scans address for i +1, -1 dont hav any effect on codeQ2.main(int argc, char *argv[]){ (main && argc) ? main(argc-1, NULL) : return 0;}a. Runtime error.b. Compile error. Illegal syntaxc. Gets into Infinite loopd. None of the above Ans: b) illegal syntax for using returnQ3.main(){ int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i);}a. Runtime error.b. 100c. Some Integer not 100d. None of the above
Ans: d) 0Q4.main(){ int i = 0xff ; printf("\n%d", i<<2);}a. 4b. 512c. 1020d. 1024
Ans: c) 1020
Q5. #define SQR(x) x * xmain(){ printf("%d", 225/SQR(15));}a. 1b. 225c. 15d. none of the above Ans: b) 225Q6.union u{ struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i;}u;main(){ u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l);}a. 4, 4, 0b. 0, 0, 0c. 100, 4, 0d. 40, 4, 0
Ans: c) 100, 4, 0Q7.union u{ union u { int i; int j; }a[10]; int b[10];}u;main(){ printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a));// printf("%d", sizeof(u.a[4].i));}a. 4, 4, 4b. 40, 4, 4c. 1, 100, 1d. 40 400 4
Ans: 20, 200, error for 3rd printfQ8.main(){ int (*functable[2])(char *format, ...) ={printf, scanf}; int i = 100; (*functable[0])("%d", i); (*functable[1])("%d", i); (*functable[1])("%d", i); (*functable[0])("%d", &i);}a. 100, Runtime error.b. 100, Random number, Random number, Random number.c. Compile errord. 100, Random number Q9.main(){ int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p}a. Runtime error.b. 1.00000c. Compile errord. 0.00000
Ans: c) Error becoz i/(*p) is 25/25 i.e 1 which is int & printed as a float, So abnormal program termination, runs if (float) i/(*p) -----> Type CastingQ10.main(){ int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j);}a. Runtime error.b. 0, 0c. Compile errord. the first two values entered by the user
Ans: d) two values entered, 3rd will be null pointer assignmentQ11.main(){ char *p = "hello world"; p[0] = 'H'; printf("%s", p);}a. Runtime error.b. “Hello world”c. Compile errord. “hello world”
Ans: b) Hello worldQ12.main(){ char * strA; char * strB = I am OK; memcpy( strA, strB, 6);}a. Runtime error.b. I am OKc. Compile errord. I am O Ans: c) I am OK is not in " "
Q13. How will you print % character?a. printf(“\%”)b. printf(“\\%”)c. printf(“%%”)d. printf(“\%%”)
Ans: c) printf(" %% ");Q14.const int perplexed = 2;#define perplexed 3main(){ #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed);}a. 0b. 2c. 4d. none of the above Ans: c)Q15.struct Foo{ char *pName;};main(){ struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName);}a. Your Nameb. compile errorc. Named. Runtime error
Ans a)Q16.struct Foo{ char *pName; char *pAddress;};main(){ struct Foo *obj = malloc(sizeof(struct Foo));clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress);}a. Your Name, Your Addressb. Your Address, Your Addressc. Your Name Your Named. None of the above
Ans: d) printd Nothing, as after free(obj), no memory is there containing obj->pName & pbj->pAddressQ17.main(){ char *a = "Hello "; char *b = "World";clrscr(); printf("%s", strcat(a,b));}a. Hellob. Hello Worldc. HelloWorldd. None of the above
Ans: b)Q18.main(){ char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b));}a. “Hello”b. “Hello World”c. “HelloWorld”d. None of the above Ans: d) World, copies World on a, overwrites Hello in a.Q19.void func1(int (*a)[10]){ printf("Ok it works");}void func2(int a[][10]){ printf("Will this work?");} main() { int a[10][10]; func1(a); func2(a);}a. Ok it worksb. Will this work?c. Ok it worksWill this work?d. None of the above Ans: c)Q20.main(){ printf("%d, %d", sizeof('c'), sizeof(100));}a. 2, 2b. 2, 100c. 4, 100d. 4, 4 Ans: a) 2, 2Q21.main(){ int i = 100; clrscr(); printf("%d", sizeof(sizeof(i)));}a. 2b. 100c. 4d. none of the above
Ans: a) 2Q22. main(){ int c = 5; printf("%d", mainc);}a. 1b. 5c. 0d. none of the above Ans: a) 1, if we use mainc then error, illegal use of pointer
Q23.main(){ char c; int i = 456; clrscr(); c = i; printf("%d", c);}a. 456b. -456c. random numberd. none of the above Ans: d) -56Q24.void main (){ int x = 10; printf ("x = %d, y = %d", x,--x++);}a. 10, 10b. 10, 9c. 10, 11d. none of the above
Ans: d) Lvalue requiredQ25.main(){ int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i);}a. 20, 10, 20, 10b. 20, 9, 20, 10c. 20, 9, 19, 10d. 19, 9, 20, 10 Ans: c)Q26.main(){ int x=5; clrscr(); for(;x==0;x--) { printf("x=%d\n”", x--); }}a. 4, 3, 2, 1, 0b. 1, 2, 3, 4, 5c. 0, 1, 2, 3, 4d. none of the above Ans: d) prints nothing, as condition x==0 is FalseQ27main(){ int x=5; for(;x!=0;x--) { printf("x=%d\n", x--); }}a. 5, 4, 3, 2,1b. 4, 3, 2, 1, 0c. 5, 3, 1d. none of the above Ans: d) Infinite loop as x is decremented twice, it never be 0 and loop is going on & on Q28main(){ int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); }}a. 5, 3, 1b. 5, 2, 1,c. 5, 3, 1, -1, 3d. –3, -1, 1, 3, 5
Ans: prints nothing, as condition in loop is false.Q29.main(){ { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); }}a. 256, 256b. 512, 512c. 256, 512d. Compile error Ans: 256, 512, becoz these r different blocks, so declaration allowedQ30.main(){ int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); }}a. 5, 4, 3, 2, 1b. 0, 1, 2, 3, 4c. 0, 1, 2, 4, 8d. 1, 2, 4, 8, 16
Ans: d) L does't make any diff.Q31.main(){ signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); }}a. 512, 256, 128, 64, 32b. 256, 128, 64, 32, 16c. 128, 64, 32, 16, 8d. 64, 32, 16, 8, 4 Ans: b)Q32.main(){ signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); }}a. 512, 256, 0, 0, 0b. 256, 256, 0, 0, 0c. 512, 512, 512, 512, 512d. 256, 256, 256, 256, 256
Ans: d) bit's value is not changedQ33.main(){ if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); }}a. OK I am doneb. OK I am gonec. compile errord. none of the above Ans: a)Q34main(){ if ((10) && (01)) { printf("OK I am done."); } else { printf("OK I am gone."); }}a. OK I am doneb. OK I am gonec. compile errord. none of the above Ans: a)Q35main(){ signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); }}a. 0, 0b. 0, 513c. 512, 0d. 0, -513 Ans: d)
Q1.main(){ int i; clrscr(); printf("%d", &i)+1; scanf("%d", i)-1;}a. Runtime error.b. Runtime error. Access violation.c. Compile error. Illegal syntaxd. None of the above Ans: d, printf( ) prints address/garbage of i, scanf() dont hav & sign, so scans address for i +1, -1 dont hav any effect on codeQ2.main(int argc, char *argv[]){ (main && argc) ? main(argc-1, NULL) : return 0;}a. Runtime error.b. Compile error. Illegal syntaxc. Gets into Infinite loopd. None of the above Ans: b) illegal syntax for using returnQ3.main(){ int i; float *pf; pf = (float *)&i; *pf = 100.00; printf("\n %d", i);}a. Runtime error.b. 100c. Some Integer not 100d. None of the above
Ans: d) 0Q4.main(){ int i = 0xff ; printf("\n%d", i<<2);}a. 4b. 512c. 1020d. 1024
Ans: c) 1020
Q5. #define SQR(x) x * xmain(){ printf("%d", 225/SQR(15));}a. 1b. 225c. 15d. none of the above Ans: b) 225Q6.union u{ struct st { int i : 4; int j : 4; int k : 4; int l; }st; int i;}u;main(){ u.i = 100; printf("%d, %d, %d",u.i, u.st.i, u.st.l);}a. 4, 4, 0b. 0, 0, 0c. 100, 4, 0d. 40, 4, 0
Ans: c) 100, 4, 0Q7.union u{ union u { int i; int j; }a[10]; int b[10];}u;main(){ printf("\n%d", sizeof(u)); printf(" %d", sizeof(u.a));// printf("%d", sizeof(u.a[4].i));}a. 4, 4, 4b. 40, 4, 4c. 1, 100, 1d. 40 400 4
Ans: 20, 200, error for 3rd printfQ8.main(){ int (*functable[2])(char *format, ...) ={printf, scanf}; int i = 100; (*functable[0])("%d", i); (*functable[1])("%d", i); (*functable[1])("%d", i); (*functable[0])("%d", &i);}a. 100, Runtime error.b. 100, Random number, Random number, Random number.c. Compile errord. 100, Random number Q9.main(){ int i, j, *p; i = 25; j = 100; p = &i; // Address of i is assigned to pointer p printf("%f", i/(*p) ); // i is divided by pointer p}a. Runtime error.b. 1.00000c. Compile errord. 0.00000
Ans: c) Error becoz i/(*p) is 25/25 i.e 1 which is int & printed as a float, So abnormal program termination, runs if (float) i/(*p) -----> Type CastingQ10.main(){ int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j);}a. Runtime error.b. 0, 0c. Compile errord. the first two values entered by the user
Ans: d) two values entered, 3rd will be null pointer assignmentQ11.main(){ char *p = "hello world"; p[0] = 'H'; printf("%s", p);}a. Runtime error.b. “Hello world”c. Compile errord. “hello world”
Ans: b) Hello worldQ12.main(){ char * strA; char * strB = I am OK; memcpy( strA, strB, 6);}a. Runtime error.b. I am OKc. Compile errord. I am O Ans: c) I am OK is not in " "
Q13. How will you print % character?a. printf(“\%”)b. printf(“\\%”)c. printf(“%%”)d. printf(“\%%”)
Ans: c) printf(" %% ");Q14.const int perplexed = 2;#define perplexed 3main(){ #ifdef perplexed #undef perplexed #define perplexed 4 #endif printf("%d",perplexed);}a. 0b. 2c. 4d. none of the above Ans: c)Q15.struct Foo{ char *pName;};main(){ struct Foo *obj = malloc(sizeof(struct Foo)); clrscr(); strcpy(obj->pName,"Your Name"); printf("%s", obj->pName);}a. Your Nameb. compile errorc. Named. Runtime error
Ans a)Q16.struct Foo{ char *pName; char *pAddress;};main(){ struct Foo *obj = malloc(sizeof(struct Foo));clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress);}a. Your Name, Your Addressb. Your Address, Your Addressc. Your Name Your Named. None of the above
Ans: d) printd Nothing, as after free(obj), no memory is there containing obj->pName & pbj->pAddressQ17.main(){ char *a = "Hello "; char *b = "World";clrscr(); printf("%s", strcat(a,b));}a. Hellob. Hello Worldc. HelloWorldd. None of the above
Ans: b)Q18.main(){ char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b));}a. “Hello”b. “Hello World”c. “HelloWorld”d. None of the above Ans: d) World, copies World on a, overwrites Hello in a.Q19.void func1(int (*a)[10]){ printf("Ok it works");}void func2(int a[][10]){ printf("Will this work?");} main() { int a[10][10]; func1(a); func2(a);}a. Ok it worksb. Will this work?c. Ok it worksWill this work?d. None of the above Ans: c)Q20.main(){ printf("%d, %d", sizeof('c'), sizeof(100));}a. 2, 2b. 2, 100c. 4, 100d. 4, 4 Ans: a) 2, 2Q21.main(){ int i = 100; clrscr(); printf("%d", sizeof(sizeof(i)));}a. 2b. 100c. 4d. none of the above
Ans: a) 2Q22. main(){ int c = 5; printf("%d", mainc);}a. 1b. 5c. 0d. none of the above Ans: a) 1, if we use mainc then error, illegal use of pointer
Q23.main(){ char c; int i = 456; clrscr(); c = i; printf("%d", c);}a. 456b. -456c. random numberd. none of the above Ans: d) -56Q24.void main (){ int x = 10; printf ("x = %d, y = %d", x,--x++);}a. 10, 10b. 10, 9c. 10, 11d. none of the above
Ans: d) Lvalue requiredQ25.main(){ int i =10, j = 20; clrscr(); printf("%d, %d, ", j-- , --i); printf("%d, %d ", j++ , ++i);}a. 20, 10, 20, 10b. 20, 9, 20, 10c. 20, 9, 19, 10d. 19, 9, 20, 10 Ans: c)Q26.main(){ int x=5; clrscr(); for(;x==0;x--) { printf("x=%d\n”", x--); }}a. 4, 3, 2, 1, 0b. 1, 2, 3, 4, 5c. 0, 1, 2, 3, 4d. none of the above Ans: d) prints nothing, as condition x==0 is FalseQ27main(){ int x=5; for(;x!=0;x--) { printf("x=%d\n", x--); }}a. 5, 4, 3, 2,1b. 4, 3, 2, 1, 0c. 5, 3, 1d. none of the above Ans: d) Infinite loop as x is decremented twice, it never be 0 and loop is going on & on Q28main(){ int x=5; clrscr(); for(;x<= 0;x--) { printf("x=%d ", x--); }}a. 5, 3, 1b. 5, 2, 1,c. 5, 3, 1, -1, 3d. –3, -1, 1, 3, 5
Ans: prints nothing, as condition in loop is false.Q29.main(){ { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); }}a. 256, 256b. 512, 512c. 256, 512d. Compile error Ans: 256, 512, becoz these r different blocks, so declaration allowedQ30.main(){ int i; clrscr(); for(i=0;i<5;i++) { printf("%d\n", 1L << i); }}a. 5, 4, 3, 2, 1b. 0, 1, 2, 3, 4c. 0, 1, 2, 4, 8d. 1, 2, 4, 8, 16
Ans: d) L does't make any diff.Q31.main(){ signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); }}a. 512, 256, 128, 64, 32b. 256, 128, 64, 32, 16c. 128, 64, 32, 16, 8d. 64, 32, 16, 8, 4 Ans: b)Q32.main(){ signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); }}a. 512, 256, 0, 0, 0b. 256, 256, 0, 0, 0c. 512, 512, 512, 512, 512d. 256, 256, 256, 256, 256
Ans: d) bit's value is not changedQ33.main(){ if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); }}a. OK I am doneb. OK I am gonec. compile errord. none of the above Ans: a)Q34main(){ if ((10) && (01)) { printf("OK I am done."); } else { printf("OK I am gone."); }}a. OK I am doneb. OK I am gonec. compile errord. none of the above Ans: a)Q35main(){ signed int bit=512, mBit; { mBit = ~bit; bit = bit & ~bit ; printf("%d %d", bit, mBit); }}a. 0, 0b. 0, 513c. 512, 0d. 0, -513 Ans: d)

0 Comments:
Post a Comment
<< Home