total c prog bits(450)

77
What will be the output of the following C program segment? char inchar = 'A'; switch (inchar) { case 'A' : printf ("choice A \n") ; case 'B' : printf ("choice B ") ; case 'C' : case 'D' : case 'E' : default: printf ("No Choice") ; } A) No choice B) Choice A C) Choice A Choice B No choice D) Program gives no output as it is erroneous ANSWER: C Consider the following C function definition: int Trial (int a, int b, int c) { if ((a > = b) && (c < b)) return b; else if (a > = b) return Trial (a,c,b); else return Trial (b,a,c); } The function Trial: A) Finds the maximum of a, b, and c B) Finds the minimum of a, b and c C) Finds the middle number of a, b, c D) None of the above ANSWER: C The value of j at the end of the execution of the following C program. int incr (int i) { static int count = 0; count = count + i; return (count); } main () { int i,j; for (i = 0; i <=4; i++) j = incr(i); } A) 10 B) 4 C) 6 D) 7 ANSWER: A Consider the following declaration of a two-dimensional array in C: char a[100][100]; Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a[40][50] is A) 4040 B) 4050 C) 5040 D) 5050

Upload: kurumeti

Post on 19-Jul-2016

313 views

Category:

Documents


16 download

DESCRIPTION

c prog

TRANSCRIPT

Page 1: Total c Prog Bits(450)

What will be the output of the following C program segment?

char inchar = 'A';switch (inchar){case 'A' :

printf ("choice A \n") ;case 'B' :

printf ("choice B ") ;case 'C' :case 'D' :case 'E' :default:

printf ("No Choice") ;}

A) No choiceB) Choice AC) Choice A Choice B No choiceD) Program gives no output as it is erroneousANSWER: C Consider the following C function definition:

int Trial (int a, int b, int c) {

if ((a > = b) && (c < b)) return b; else if (a > = b) return Trial (a,c,b); else return Trial (b,a,c);

}The function Trial:

A) Finds the maximum of a, b, and c B) Finds the minimum of a, b and c C) Finds the middle number of a, b, c D) None of the above ANSWER: C

The value of j at the end of the execution of the following C program. int incr (int i){

static int count = 0; count = count + i; return (count);

}main (){

int i,j; for (i = 0; i <=4; i++) j = incr(i);

}A) 10 B) 4 C) 6 D) 7ANSWER: A

Consider the following declaration of a �two-dimensional array in C: char a[100][100];

Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a[40][50] is A) 4040 B) 4050 C) 5040 D) 5050

Page 2: Total c Prog Bits(450)

ANSWER: BConsider the following C-program:void foo(int n, int sum){

int k = 0, j = 0; if (n == 0) return; k = n % 10; j = n / 10; sum = sum + k; foo (j, sum); printf ("%d,", k);

}int main (){

int a = 2048, sum = 0; foo (a, sum); printf ("%d\n", sum); getchar();

}What does the above program print?

A) 8, 4, 0, 2, 14 B) 8, 4, 0, 2, 0 C) 2, 0, 4, 8, 14 D) 2, 0, 4, 8, 0ANSWER: D

Consider the following C function:int f(int n){

static int i = 1; if (n >= 5) return n; n = n+i; i++; return f(n);

}The value returned by f(1) is

A) 5 B) 6 C) 7 D) 8ANSWER: C

Consider the following C programmain(){

int x, y, m, n; scanf ("%d %d", &x, &y); /* x > 0 and y > 0 */ m = x; n = y; while (m != n) { if(m>n) m = m - n; else n = n - m; } printf("%d", n);

}The program computes

A) x + y using repeated subtractionB) x mod y using repeated subtractionC) the greatest common divisor of x & y

Page 3: Total c Prog Bits(450)

D) the least common multiple of x & yANSWER: C

Consider the following C-program:double foo (double); /* Line 1 */int main () {

double da, db; // input da db = foo (da);

}double foo (double a) {

return a;}The above code compiled without any error or warning. If Line 1 is delet

ed, the above code will show:A) no compile warning or errorB) some compiler-warnings not leading to unintended resultsC) some compiler-warnings due to type-mismatch eventually leading to unintended resultsD) compiler errorsANSWER: D

Consider line number 3 of the following C-program. int main ( ) { /* Line 1 */

int i, n; /* Line 2 */ fro (i =0, i<n, i++); /* Line 3 */

} Identify the compiler�s response about this line while creating the object

-module: A) No compilation error B) Only a lexical errorC) Only syntactic errors D) Both lexical and syntactic errorsANSWER: C

Consider these two functions and two statements S1 and S2 about them.int work1(int *a, int i, int j){

int x = a[i+2]; a[j] = x+1; return a[i+2] � 3;

} int work2(int *a, int i, int j){

int t1 = i+2; int t2 = a[t1]; a[j] = t2+1; return t2 � 3;

}S1: The transformation from work1 to work2 is valid, i.e., for any progr

am state and input arguments, work2 will compute the same output and have the same effect on program state as work1

S2: All the transformations applied to work1 to get work2 will always improve the performance (i.e reduce CPU time) of work2 compared to work1A) S1 is false and S2 is falseB) S1 is false and S2 is trueC) S1 is true and S2 is falseD) S1 is true and S2 is trueANSWER: D

What is (void*)0?A) Representation of NULL pointerB) Representation of void pointer

Page 4: Total c Prog Bits(450)

C) ErrorD) None of aboveANSWER: A

Can you combine the following two statements into one? char *p;p = (char*) malloc(100);

A) char p = *malloc(100);B) char *p = (char) malloc(100);C) char *p = (char*)malloc(100);D) char *p = (char *)(malloc*)(100);ANSWER: C In which header file is the NULL macro defined?A) stdio.hB) stddef.hC) stdio.h and stddef.hD) math.hANSWER: C How many bytes are occupied by near, far and huge pointers (DOS)?A) near=2 far=4 huge=4B) near=4 far=8 huge=8C) near=2 far=4 huge=8D) near=4 far=4 huge=8ANSWER: A If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?A) .B) &C) *D) ->ANSWER: D In a file contains the line "I am a boy\r\n" then on reading this line into the array str using fgets(). What will str contain?A) "I am a boy\r\n\0"B) "I am a boy\r\0"C) "I am a boy\n\0"D) "I am a boy"ANSWER: C What is the purpose of "rb" in fopen() function used below in the code?

FILE *fp;fp = fopen("source.txt", "rb");

A) open "source.txt" in binary mode for readingB) open "source.txt" in binary mode for reading and writingC) Create a new file "source.txt" for reading and writingD) None of aboveANSWER: A What does fp point to in the program ?

#include<stdio.h>

int main(){

FILE *fp; fp=fopen("trial", "r"); return 0;

}A) The first character in the fileB) A structure which contains a char pointer which points to the first character of a file.C) The name of the file.D) The last character in the file.

Page 5: Total c Prog Bits(450)

ANSWER: B Which of the following operations can be performed on the file "NOTES.TXT" using the below code?

FILE *fp;fp = fopen("NOTES.TXT", "r+");

A) ReadingB) WritingC) AppendingD) Read and WriteANSWER: D

To print out a and b given below, which of the following printf() statement will you use?

#include<stdio.h>

float a=3.14;double b=3.14;

A) printf("%f %lf", a, b);B) printf("%Lf %f", a, b);C) printf("%Lf %Lf", a, b);D) printf("%f %Lf", a, b);ANSWER: A

Which files will get closed through the fclose() in the following program?

#include<stdio.h>

int main(){

FILE *fs, *ft, *fp; fp = fopen("A.C", "r"); fs = fopen("B.C", "r"); ft = fopen("C.C", "r"); fclose(fp, fs, ft); return 0;

}A) "A.C" "B.C" "C.C"B) "B.C" "C.C"C) "A.C"D) Error in fclose()ANSWER: D On executing the below program what will be the contents of 'target.txt' file if the source file contains a line "To err is human"?

#include<stdio.h>

int main(){

int i, fss; char ch, source[20] = "source.txt", target[20]="target.txt", t; FILE *fs, *ft; fs = fopen(source, "r"); ft = fopen(target, "w"); while(1) { ch=getc(fs); if(ch==EOF) break; else { fseek(fs, 4L, SEEK_CUR); fputc(ch, ft); }

Page 6: Total c Prog Bits(450)

} return 0;

}A) r nB) TrhC) errD) None of aboveANSWER: B To scan a and b given below, which of the following scanf() statement will you use?

#include<stdio.h>

float a;double b;

A) scanf("%f %f", &a, &b);B) scanf("%Lf %Lf", &a, &b);C) scanf("%f %Lf", &a, &b);D) scanf("%f %lf", &a, &b);ANSWER: D Out of fgets() and gets() which function is safe to use?A) gets()B) fgets()c) puts()D) fputs()ANSWER: B

Consider the following program and what will be content of t? #include<stdio.h>

int main(){

FILE *fp; int t; fp = fopen("DUMMY.C", "w"); t = fileno(fp); printf("%d\n", t); return 0;

}A) size of "DUMMY.C" fileB) The handle associated with "DUMMY.C" fileC) Garbage valueD) Error in fileno()ANSWER: B

The number of tokens in the following C statement. printf("i = %d, &i = %x", i, &i); isA) 3 B) 26 C) 10 D) 21ANSWER: C

Consider the following C function:int f(int n){

static int r = 0; if (n <= 0) return 1; if (n > 3) { r = n; return f(n-2)+2; } return f(n-1)+r;

Page 7: Total c Prog Bits(450)

}What is the value of f(5) ?

A) 5 B) 7 C) 9 D) 18ANSWER: D

Common data Questions (13 & 14)Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r) {if (n > 0) return (n%r + foo (n/r, r ));

else return 0;}What is the return value of the function foo when it is called as foo(34

5, 10) ?A) 345 B) 12 C) 5 D) 3ANSWER: B

What is the return value of the function foo when it is called as foo(513, 2)?A) 9 B) 8 C) 5 D) 2ANSWER: D

Choose the correct option to fill ?1 and ?2 so that the program below prints an input string in reverse order. Assume that the input string is terminated by a newline character.

void reverse(void){

int c; if (?1) reverse() ; ?2

}main(){

printf ("Enter Text ") ; printf ("\n") ; reverse(); printf ("\n") ;

}A) ?1 is (getchar() != '\n'�) ?2 is getchar(c);B) ?1 is (c = getchar() ) != '\n') ?2 is getchar(c);C) ?1 is (c != �\n�) ?2 is putchar(c);D) ?1 is ((c = getchar()) != '\n') ?2 is putchar(c);ANSWER: D

The following C declarationstruct node {

int i; float j;

}; struct node *s[10] ; define s to be

A) An array, each element of which is a pointer to a structure of type nodeB) A structure of 2 fields, each field being a pointer to an array of 10 el

Page 8: Total c Prog Bits(450)

ementsC) A structure of 3 fields: an integer, a float, and an array of 10 elementsD) An array, each element of which is a structure of type node.

ANSWER: AThe most appropriate matching for the following pairsX: m=malloc(5); m= NULL; 1: using dangling pointersY: free(n); n->value=5; 2: using uninitialized pointersZ: char *p; *p = �a�; 3: lost memory is:

A) X�1 Y�3 Z-2B) X�2 Y�1 Z-3C) X�3 Y�2 Z-1D) X�3 Y�1 Z-2ANSWER: D

Consider the following C declarationstruct { short s [5]

union { float y; long z; }u;

} t; Assume that objects of the type short, float and long occupy 2 bytes, 4

bytes and 8 bytes, respectively. The memory requirement for variable t, ignoring alignment considerations, is A) 22 bytes B) 14 bytes C) 18 bytes D) 10 bytesANSWER: C

Assume the following C variable declaration int *A [10], B[10][10];

Of the following expressionsI A[2]II A[2][3]III B[1]IV B[2][3]which will not give compile-time errors if used as left hand sides of as

signment statements in a C program?A) I, II, and IV only B) II, III, and IV onlyC) II and IV only D) IV onlyANSWER: A

Consider the following C functionvoid swap (int a, int b){int temp;

temp = a; a = b; b = temp;

}In order to exchange the values of two variables x and y.

A) call swap (x, y)B) call swap (&x, &y)C) swap (x,y) cannot be used as it does not return any valueD) swap (x,y) cannot be used as the parameters are passed by valueANSWER: D

Page 9: Total c Prog Bits(450)

What does the following C-statement declare? int ( * f) (int * ) ; A) A function that takes an integer pointer as argument and returns an integer B) A function that takes an integer as argument and returns an integer pointer C) A pointer to a function that takes an integer pointer as argument and returns an integer.D) A function that takes an integer pointer as argument and returns a function pointerANSWER: C

What does the following program print?#include<stdio.h>void f(int *p, int *q){

p = q; *p = 2;

}int i = 0, j = 1;int main(){

f(&i, &j); printf("%d %d \n", i, j); getchar(); return 0;

}A) 2 2 B) 2 1 C) 0 1 D) 0 2ANSWER: D

What does the following fragment of C-program print?char c[] = "GATE2011";char *p =c;printf("%s", p + p[3] - p[1]);

A) GATE2011 B) E2011 C) 2011 D) 011ANSWER: C

Consider the following C program segment:char p[20];char *s = "string";int length = strlen(s);int i;for (i = 0; i < length; i++)

p[i] = s[length � i];printf("%s",p);The output of the program is

A) gnirts B) gnirtC) string D) no output is printedANSWER: D

Common Data Question for 25 & 26Consider the following C programint a, b, c = 0;void prtFun (void);int main (){

Page 10: Total c Prog Bits(450)

static int a = 1; /* line 1 */ prtFun(); a += 1; prtFun(); printf ( "\n %d %d " , a, b) ;

}void prtFun (void){

static int a = 2; /* line 2 */ int b = 1; a += ++b; printf (" \n %d %d " , a, b);

}What output will be generated by the given code segment?

A) 3 1 4 14 2

B) 4 2 6 1

6 1 C) 4 2

6 2 2 0

D) 3 15 25 2

ANSWER: CWhat output will be generated by the given code segment if:Line 1 is replaced by �auto int a = 1;Line 2 is replaced by �register int a = 2;

A) 3 1 4 1 4 2

B) 4 2 6 1 6 1

C) 4 2 6 2 2 0

D) 4 24 22 0

ANSWER: DWhat is printed by the following C program?int f(int x, int *py, int **ppz){

int y, z; **ppz += 1; z = **ppz; *py += 2; y = *py; x += 3; return x + y + z;

}void main(){

int c, *b, **a; c = 4; b = &c; a = &b;

Page 11: Total c Prog Bits(450)

printf( "%d", f(c,b,a)); getchar();

}A) 18 B) 19 C) 21 D) 22ANSWER: B

What does the following fragment of C program print? char c[] = "GATE2011";

char *p = c; printf("%s", p + p[3] - p[1]);A) GATE2011B) E2011C) 2011D) 011ANSWER: C

The smallest element of an array's index is called its A) Lower bound.B) Upper bound.C) Range.D) Extraction.ANSWER: A

O(N)(linear time) is better than O(1) constant time.A) True B) FalseANSWER: B

For 'C' programming languageA) Constant expressions are evaluated at compileB) String constants can be concatenated at compile timeC) Size of array should be known at compile timeD) All of theseANSWER: D

What is the maximun number of dimensions an array in C may have?A) TwoB) EightC) TwentyD) Theoratically no limit. The only practical limits are memory size and compilersANSWER: D

If x is an array of interger, then the value of &x[i] is same asA) &x[i-1]+sizeof(int)B) x+sizeof(int)*iC) x+iD) none of theseANSWER: C

If S is an array of 80 characters, then the value assigned to S through the statement scanf("%s",S) with input 1 2 3 4 5 would beA) "12345"B) nothing since 12345 is an integerC) S is an illegal name for stringD) %s cannot be used for reading in values of SANSWER: A

Size of the array need not be specified, whenA) Initialization is a part of definitionB) It is a declaratrionC) It is a formal parameterD) All of theseANSWER: D

A one dimensional array A has indices 1....75.Each element is a string a

Page 12: Total c Prog Bits(450)

nd takes up three memory words. The array is stored starting at location 1120 decimal. The starting address of A[49] isA) 1167B) 1164C) 1264D) 1169ANSWER: C

Minimum number of interchange needed to convert the array 89,19,40,14,17,12,10,2,5,7,11,6,9,70, into a heap with the maximum element at the root isA) 0B) 1C) 2D) 3ANSWER: C

Which of the following is an illegal array definition?A) Type COLOGNE:(LIME,PINE,MUSK,MENTHOL); var a:array[COLOGNE]of REAL;B) var a:array[REAL]of REAL;C) var a:array['A'..'Z']of REAL;D) var a:array[BOOLEAN]of REAL;ANSWER: B

#include<stdio.h>#include<stdarg.h>void fun1(int num, ...);void fun2(int num, ...);

int main(){

fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0;

}void fun1(int num, ...){

char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str);

}void fun2(int num, ...){

va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num);

}A) Dogs 12B) Cats 14C) Boys 13D) Apple 12ANSWER: A

#include<stdio.h>#include<stdarg.h>fun(...);

int main(){

fun(3, 7, -11.2, 0.66); return 0;

}

Page 13: Total c Prog Bits(450)

fun(...){

va_list ptr; int num; va_start(ptr, n); num = va_arg(ptr, int); printf("%d", num);

}A) Error: fun() needs return typeB) Error: ptr Lvalue requiredC) Error: Invalid declaration of fun(...)D) No errorANSWER: C

#include<stdio.h>#include<stdarg.h>void display(int num, ...);

int main(){

display(4, 'A', 'a', 'b', 'c'); return 0;

}void display(int num, ...){

char c; int j; va_list ptr; va_start(ptr, num); for(j=1; j<=num; j++) { c = va_arg(ptr, char); printf("%c", c); }

}A) Error: unknown variable ptrB) Error: Lvalue required for parameterC) No error and print A a b cD) No error and print 4 A a b cANSWER: C The value of a resistor creating thermal noise is doubled the noise power generated is therefore A) Halved B) Quadrupled C) UnchangedD) DoubledANSWER: C

De-emphasis circuit is usedA) After modulationB) Prior to modulationC) To de-emphasis low frequency component D) To de-emphasis high frequency component ANSWER: D

The capacity of a channel is A) Number of digits used in coding B) Volume of information it can take C) Maximum rate of information transmissionD) Bandwidth required for informationANSWER: C

void main() { int const *p=5;

Page 14: Total c Prog Bits(450)

printf("%d"' ++(*p)); }A) 6B) 5c) Garbage valueD) compilier ErrorANSWER: D

main(){static int var=5;printf("%d"'var--);if(var)main();

A) 1.55555B) 54321C) infinite loopD) NoneANSWER: B

main(){

char *p;printf("%d%d",size of(*p),size of(p));

A) 11B) 12C) 21D) 22ANSWER: B

main(){int c=--2;printf("c=%d",c);}

A) 1B) -2C) 2D) ErrorANSWER: B

#define int charmain(){inti=65;printf("size of(i)=%d",size of(i));}

A) size of(i)=2B) size(i)=1C) compiler errorD) NoneANSWER: B

main() {

char string[]="Helloworld"display(strings);}

void diaplay(char*string){printf("%s",string)}

A) compiler ErrorB) HelloworldC) can't say

Page 15: Total c Prog Bits(450)

D) NoneANSWER: A #define square(*)***

main(){

int i;i=64/squqre(4);printf("%d",i);}

A) 4B) 64C) 16D) NoneANSWER: B

#include<stdio.h>#define a 10main(){#define a 50printf("%d",a);}

A) 50B) 10C) compile ErrorD) NoneANSWER: A

#define clrscr() 100main(){clrscr();

printf("%d/n");clrscr();

A) 0B) 1C) 100D) NoneANSWER: C main()

{int i=1;j=2;switch(i){

case i:printf("GOOD");break;case j;printf("BAD");break;}}

a) Goodb) Badc) GOOD BadD) ErrorANSWER: D

main(){int i=0;

for(;i++;prntf("%d",i));printf("%d",i);

}A) 1B) 11C) 12

Page 16: Total c Prog Bits(450)

D) ErrorANSWER: A

main() {

extern int i;i=20;printf("%d",size of(i));}

A) 20B) 2C) compile ErrorD) Linear ErrorANSWER: D

main(){int i=0;j=0;

if(i&&j++)printf("%d..%d",i++,j);printf("%d..%d",i,j);}

A) 0..1B) 1..0C) 0..0D) 1..1ANSWER: D

void main(){static int i=5;if(--i)

{main();printf("%d",i);}}

A) 54321B) 0000C) infiniteloopD) NoneANSWER: B

#includemain(){register i=5;char j[]=("hello");printf("%s%d",j,i);}

A) Hello 5B) Hello garbage valueC) ErrorD) NoneANSWER: A

What will be output if you will compile and execute the following c code?

void main(){int a=2;if(a==2){

a=~a+2<<1;

Page 17: Total c Prog Bits(450)

printf("%d",a);}else{

break;}}

A) It will print nothing.B) -3C) compiler errorD) 1ANSWER: C

What will be output of the following c program?#include<stdio.h>int main(){int goto=5;printf("%d",goto);return 0;}

A) 5B) **C) **D) Compilation errorANSWER: D

What will be output of the following c program?#include<stdio.h>int main(){long int 1a=5l;printf("%ld",1a);

return 0;}

A) 5B) 51C) 6D) Compilation errorANSWER: D

What will be output of the following c program?#include<stdio.h>int main(){

int _=5; int __=10; int ___; ___=_+__; printf("%i",___); return 0;

}

A) 5B) 10C) 15D) Compilation errorANSWER: C

#include<stdio.h>int main(){

int max-val=100; int min-val=10; int avg-val; avg-val = max-val + min-val / 2;

Page 18: Total c Prog Bits(450)

printf("%d",avg-val); return 0;

}A) 55B) 105C) 60D) Compilation errorANSWER: DWhat will be output of the following c program?

#include<stdio.h>int main(){

int class=150; int public=25; int private=30; class = class >> private - public; printf("%d",class); return 0;

}

A) 1B) 2C) 4D) Compilation errorANSWER: C

What will be output of the following c program?#include<stdio.h>int main(){

int abcdefghijklmnopqrstuvwxyz123456789=10; int abcdefghijklmnopqrstuvwxyz123456=40; printf("%d",abcdefghijklmnopqrstuvwxyz123456); return 0;

}

A) 10B) 40C) 50D) Compilation error

main() {

char string[]="Helloworld"display(strings);}

void diaplay(char*string){printf("%s",string)}

A) compiler ErrorB) HelloworldC) can't sayD) NoneANSWER: A #define square(*)***

main(){

int i;i=64/squqre(4);printf("%d",i);}

Page 19: Total c Prog Bits(450)

A) 4B) 64C) 16D) NoneANSWER: B

What will be output if you will compile and execute the following c code?

void main(){ int a=10; printf("%d %d %d",a,a++,++a);

}A) 12 11 11B) 12 10 10C) 11 11 12D) 10 10 12ANSWER: A

What will be output if you will compile and execute the following c code?

void main(){ char *str="Hello world"; printf("%d",printf("%s",str));

}

A) 11Hello worldB) 10Hello worldC) Hello world10D) Hello world11ANSWER: D

#include<stdio.h>#define a 10main(){#define a 50printf("%d",a);}

A) 50B) 10C) compile ErrorD) NoneANSWER: A

#define clrscr() 100main(){clrscr();

printf("%d/n");clrscr();

A) 0B) 1C) 100D) NoneANSWER: C

What will be output if you will compile and execute the following c code?

#include "stdio.h"#include "string.h"void main(){

char *str=NULL;

Page 20: Total c Prog Bits(450)

strcpy(str,"cquestionbank");printf("%s",str);}

A) cquestionbankB) cquestionbank\0C) (null)D) It will print nothingANSWER: C

What will be output if you will compile and execute the following c code?

#include "stdio.h"#include "string.h"void main(){int i=0;for(;i<=2;)printf(" %d",++i); }

A) 0 1 2B) 0 1 2 3C) 1 2 3D) Compiler errorANSWER: C main()

{int i=1;j=2;switch(i){

case i:printf("GOOD");break;case j;printf("BAD");break;}}

A) GoodB) BadC) GOOD BadD) ErrorANSWER: D

main(){int i=0;

for(;i++;prntf("%d",i));printf("%d",i);

}A) 1B) 11C) 12D) ErrorANSWER: A

main() {

extern int i;i=20;printf("%d",size of(i));}

A) 20B) 2C) compile ErrorD) Linear Error

Page 21: Total c Prog Bits(450)

ANSWER: Dmain(){int i=0;j=0;

if(i&&j++)printf("%d..%d",i++,j);printf("%d..%d",i,j);}

A) 0..1B) 1..0C) 0..0D) 1..1ANSWER: D

void main(){static int i=5;if(--i)

{main();printf("%d",i);}}

A) 54321B) 0000C) infiniteloopD) NoneANSWER: B

What will be output if you will compile and execute the following c code?

void main(){int x;for(x=1;x<=5;x++);printf("%d",x); }

A) 4B) 5C) 6D) Compiler errorANSWER: C

#includemain(){register i=5;char j[]=("hello");printf("%s%d",j,i);}

A) Hello 5B) Hello garbage valueC) ErrorD) NoneANSWER: A

main(){int i=abc(10);

printf("%d\n",--i);}

int abc(int i){return(i++);

Page 22: Total c Prog Bits(450)

}A) 10B) 9C) 11D) NoneANSWER: B

void main(){static int i=i++,j=j++,k=k++;printf("%d%d%d",i,j,k);}

A) 111B) 000C) Garbage valueD) ErrorANSWER: A

#define pnod(a,b) a*bmain(){int x=3,y=4;printf("%d,pnod(x+2,y-1));}

A) 15B) 10C) 12D) 11ANSWER: B

main(){char p[]="%d\n";p[1]='c';printf(p,65);

A) 65B) Cc) AD) ErrorANSWER: C

What is the return value of f( p,p) if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value. int f( int & x, int c) { c= c- 1;

If( c== 0) return 1; X= x+ 1; return f (x,c) * x;

} A) 3024 B) 6561 C) 55440 D) 161051ANSWER: C

What will be output if you will compile and execute the following c code?

void main(){printf("%d",sizeof(5.2));}

A) 2B) 4

Page 23: Total c Prog Bits(450)

C) 8D) 10ANSWER: C

What will be the output of the following program ?#includevoid main(){ int a = 2;switch(a){ case 1:printf("goodbye"); break;case 2:continue;case 3:printf("bye");}}

A) errorB) goodbyeC) byeD) byegoodbyeANSWER: A

void main(){ double far* p,q;

printf("%d",sizeof(p)+sizeof q); }

A) 12B) 8C) 4D) 1ANSWER: A

int i = 4;switch (i){default: ;case 3:i += 5;if ( i == 8) {i++;if (i == 9) break;i *= 2; } i -= 4; break; case 8:i += 5;break;}printf("i = %d\n", i);

What will the output of the sample code above be?A) i = 5B) i = 8C) i = 9D) i = 10ANSWER: A

long factorial (long x){

Page 24: Total c Prog Bits(450)

return x * factorial(x - 1);}With what do you replace the ???? to make the function shown above retur

n the correct answer?

A) if (x == 0) return ;B) return 1;C) if (x >= 2) return 2;D) if (x <= 1) return 1;ANSWER: D

What will be output of the following c program?#include<stdio.h>int main(){

int __SMALL__ = 11; int y; y= __SMALL__ < 5;

printf("%d",y); return 0;

}

A) 11B) 5C) 0D) Compilation errorANSWER: D

What will be output of the following c program?#include<stdio.h>int main(){

int __BIG__ = 32; int y;

y= __BIG__ && 8;printf("%d",y);return 0;}

A) 32B) 8C) 1D) Compilation errorANSWER: C

What will be output of the following c program?#include<stdio.h>static num=5;int num;extern int num;int main(){

printf("%d",num); return 0;

}

A) 5B) 10C) 0D) Compilation errorANSWER: A

#include<stdio.h>static num=5;extern int num;int main(){

printf("%d",num);

Page 25: Total c Prog Bits(450)

return 0;}int num =25;

A) 0B) 5C) 25D) Compilation error ANSWER: D

What will be output of the following c program?#include<stdio.h>static num;int main(){

printf("%d",num); return 0;

}int num =25;

A) 0B) 1C) 25D) Compilation errorANSWER: C

#define max 5;void main(){

int i=0;i=max++;printf("%d",i++);}

A) 5B) 6C) 7D) 0ANSWER: D int i = 4;

switch (i){default: ;case 3:i += 5;if ( i == 8) {i++;if (i == 9) break;i *= 2; } i -= 4; break; case 8:i += 5;break;}printf("i = %d\n", i);What will the output of the sample code above be?

A) i = 5B) i = 8C) i = 9D) i = 10ANSWER: A

#include<stdio.h>int xyz=10;

Page 26: Total c Prog Bits(450)

int main(){ int xyz=20; printf("%d",xyz); return 0;

}

A) 10B) 20C) 30D) Compilation errorANSWER: B

#include<stdio.h>int main(){

int xyz=20; int xyz; printf("%d",xyz); return 0;

}

A) 20B) 0C) GarbageD) Compilation errorANSWER: D

#include<stdio.h>int main(){

int xyz=20;{ int xyz=40; } printf("%d",xyz); return 0;

}

A) 20B) 40C) 0D) Compilation errorANSWER: A

What will be output of the following c program?#include<stdio.h>int main(){

int main = 80; printf("%d",main); return 0;

}

A) 80B) 0C) Garbage valueD) Compilation errorANSWER: A

#include<stdio.h>int main(){

struct a{ int a; }; struct a b={10}; printf("%d",b.a); return 0;

}

Page 27: Total c Prog Bits(450)

A) 0B) 10C) Garbage valueD) Compilation errorANSWER: B

What will be output of the following c program?#include<stdio.h>int main(){

int ABC=10; printf("%d",abc); return 0;

}

A) 10B) 0C) 5D) Compilation errorANSWER: D #include

void func(){int x = 0;static int y = 0;x++; y++;printf( "%d -- %d\n", x, y );}int main(){func();func();return 0;}What will the code above print when it is executed?

A) 1 -- 11 -- 1B) 1 -- 12 -- 1C) 1 -- 12 -- 2D) 1 -- 11 � 2ANSWER: D

What will be output of the following c program?#include<stdio.h>int main(){

int printf=12; printf("%d",printf); return 0;

}

A) 12B) 0C) 5D) Compilation errorANSWER: D What will be the value of `a` after the following code is executed

#define square(x) x*xa = square(2+3)

A) 25B) 13C) 11D) 0ANSWER: C

Page 28: Total c Prog Bits(450)

#include<stdio.h>int main(){

int EOF=12; printf("%d",EOF); return 0;

}

A) 12B) 0C) 5D) Compilation errorANSWER: D

#includevoid main(){int a = 36, b = 9;printf("%d",a>>a/b-2);}

A) 9B) 7C) 5D) none of theseANSWER: A

What will be the output of the following statements ?int a = 4, b = 7,c; c = a = = b; printf("%i",c);

A) 0B) errorC) 1D) garbage valueANSWER: A

What will be the output of the following statements ?int a = 5, b = 2, c = 10, i = a>bvoid main(){ printf("hello"); main(); }

A) 1B) 2C) infinite number of timesD) none of theseANSWER: c

What will be the output of the following statements ?int x[4] = {1,2,3}; printf("%d %d %D",x[3],x[2],x[1]);

A) 03%DB) 000C) 032D) 321ANSWER: c What will be the output of following code ? #include<stdio.h> void main( ) { char suite =3; switch(suite) { case 1: printf("ALL QUIZ");

Page 29: Total c Prog Bits(450)

case 2: printf("All quiz is great"); default: printf("All quiz contains MCQs"); } printf("Are you like All quiz ?"); } A) ALL QUIZB) All quiz is greatC) All quiz contains MCQsD) All quiz is great Are you like Al quiz ?ANSWER: D

What will be the output of following code ? void main( ) { int c=3; switch(c) { case '3': printf("Hi"); break; case 3: printf("Hello"); break; default: printf("How r u ?"); } }

A) HiB) HelloC) How r u ?D) None of aboveANSWER: B

What will be the output of following program ? void main( ) { int 1=3; switch(i) { case 0: printf("I am here"); case 1+0: printf("I m in second case"); case 4/2: printf("I m in third case"); case 8%5: printf("Good bye"); } }

A) All case statements will be executedB) I am hereC) Good byeD) I am in third caseANSWER: C

What will be output if you will compile and execute the following c code

Page 30: Total c Prog Bits(450)

?

#include "stdio.h"#include "string.h"void main(){

char c='\08';printf("%d",c); }

A) 8B) �8�C) compiler errorD) nullANSWER: C

What will be the output of following ? void main( ) { int suite =1; switch(suite); { case 0: printf("Its morning time"); case 1: printf("Its evening time"); } }

A) ErrorB) Its morning timeC) Its evening timeD) None of aboveANSWER: A

What will be output if you will compile and execute the following c code?

#define call(x,y) x##yvoid main(){int x=5,y=10,xy=20;printf("%d",xy+call(x,y));}

A) 35B) 510C) 15D) 40ANSWER: D

What will be output if you will compile and execute the following c code?

int * call();void main(){int *ptr;ptr=call();clrscr();printf("%d",*ptr); }int * call(){int a=25;a++;return &a;}

A) 25B) 26

Page 31: Total c Prog Bits(450)

C) Any addressD) Garbage valueANSWER: D

What will be the output of following program ? #include<stdio.h> int main( ) { int i=2,j=3,k,l; float a,b; k = i/j * j; l = j/i * j; a = i/j * j; b = j/i * i; printf("%d %d%f%f\n",k,l,a,b); return 0; }

A) 3, 0, 0, 0B) 0, 3, 0.000000, 2.000000C) 0,0,0,0D) ErrorANSWER: B

What will be the output of following program ? #incllude<stdio.h> int main( ) { int a,b; a = -3 - - 25; b = -3 - - (-3); printf("a=%d b=%d\n",a,b); return 0; }A) a = 22 b = -6B) a = -6 b = 22C) a = 3 b = 3D) No OutputANSWER: A

What will be the output of following program ? #include<stdio.h> int main( ) { float a=5,b=2; int c,d; c =a%d; d =a/2; printf("%d\n",d); return 0; } A) 3B) 2C) ErrorD) None of aboveANSWER: C

What is error in following declaration?struct outer{int a;struct inner{char c;};};

Page 32: Total c Prog Bits(450)

A) Nesting of structure is not allowed in c.B) It is necessary to initialize the member variable.C) Inner structure must have name.D) Outer structure must have name.ANSWER: C

What will be the output of program ? #include<stdio.h> int main( ) { printf("nn /n/n nn/n"); return 0; } A) NothingB) nn /n/n nnC) nn /n/nD) ErrorANSWER: B

What will be the output of program ? #include<stdio.h> int main( ) { int a,b; printf("Enter two values of a and b"); scanf("%d%d",&a,&b); printf("a=%d b=%d"a,b); return 0; }A) a = 0 b = 0B) a = 1 b = 1C) Values you enteredD) None of aboveANSWER: C

A character variable can at a time store ?A) 1 characterB) 8 characterC) 254 characterD) None of aboveANSWER: A

The maximum value that an integer constant can have is ?A) -32767B) 32767C) 1.7014e + 38D) -1.7014e + 38ANSWER: B

What will be output if you will compile and execute the following c code?

void main(){int array[]={10,20,30,40};printf("%d",-2[array]); }

(A) -60(B) -30(C) 60(D) Garbage valueANSWER: B

Which of the following is false in C ?A) Keywords cannot be used as variable namesB) Variable names can contain a digit

Page 33: Total c Prog Bits(450)

C) Variable names do not contain a blank spaceD) Capital letters can be used in variable namesANSWER: A

On which if the following operator can % operator NOT be used ?A) int variableB) float variableC) int constantD) All of above

What is the output of the following code?

#includevoid main(){int s=0;while(s++<10)# define a 10main(){printf("%d..",a);foo();printf("%d",a);}void foo(){#undef a#define a 50

A) 10..10B) 10..50C) ERRORD) 0ANSWER: C

void main(){int a=10,b=20;char x=1,y=0;if(a,b,x,y){printf("EXAM");}}What is the output?

A) XAM is printedB) exam is printedC) Compiler ErrorD) Nothing is printedANSWER: C

int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};What value does testarray[2][1][0] in the sample code above contain?

A) 11B) 7C) 5D) 9ANSWER: A

The minimum number of temporary variables needed to swap the contents of two variables is?A) 1B) 2C) 3D) 0ANSWER: D

Page 34: Total c Prog Bits(450)

Consider the function?find(int x,int y){return((x<y)?0:(x-y)):}Let a,b are two non negative integers.The call(find(a,find(a,b))

A) maximum of a,bB) positive diff of a,bC) sum of a,bD) minimum of a,bANSWER: D

Let a,b are two non negative integers.which of the following calls finds the positive diff of a,b?A) find(a,b)+find(b,a)B) find(a,find(a,b))C) a+find(a,b)D) b+find(a,b)ANSWER: A

if an integer needs two bytes of storage then maximum value of an unsigned integer is?A) 2pow16-1B) 2pow15-1C) 2pow16D) 2pow15ANSWER: A

if an integer needs two bytes of storage then maximum value of an signed integer is?A) 2pow16-1B) 2pow15-1C) 2pow16D) 2pow15ANSWER: B

printf("%d",printf("tim"));?A) results in a syntax errorB) outputs tim3C) output garbageD) prints timANSWER: B

Consider the statement: putchar(getchar()));

putchar(getchar())); if a,b is the input,output will beA) an errorB) this can't be the inputC) abD) a bANSWER: B

printf("%c",100);?A) prints 100B) prints the ASCII equivalent of 100C) prints garbageD) NoneANSWER: B

What will be the output of the following C program segment? char inChar = �A� ;

switch ( inChar ) { case �A� : printf (�Choice A\ n�) ; case �B� : case �C� : printf (�Choice B�) ; case �D� : case �E� : default : printf ( � No Choice� ) ; }

A) No Choice

Page 35: Total c Prog Bits(450)

B) Choice A C) Choice A Choice B No Choice D) Program gives no output as it is erroneousAnswer:c

The declaration float f[][3]={{1.0},{2.0},{3.0}}; represents _________.A) a one-by-three array.B) a three-by-one array.C) a three-by-three array.D) a one-by-one-array.Answer: C

A char array with the string value �aeiou� can be initialized as ___________.A) char s[]={�a�,�e�,�i�,�o�,�u�};B) char s[]=�aeiou�;C) char s[]={�a�, �e�,�i�,�o�,�u�,�\0�};D) both 1 and 2.Answer: D

The program execution starts from __________.A) the function which is first defined.B) main() function.C) the function which is last defined.D) the function other than main().Answer: B

How many main() functions can be defined in a C program?A) 1.B) 2.C) 3.D) any number of times.Answer: A

A function is identified by an open parenthesis following ________.A) a keyword.B) an identifier other than keywords.C) an identifier including keywords.D) an operator.Answer: C

A function with no action ________.A) is an invalid function.B) produces syntax error.112-C ProgrammingC) is allowed and is known as dummy function.D) returns zero.Answer: C

Parameters are used _________.A) to return values from the called function.B) to send values from the calling function.C) both 1 and 2.D) to specify the data type of the return value.Answer: C

The default return data type in function definition is _________.A) void.B) int.C) float.D) char.Answer: B

Identify the correct statement.A) A function can be defined more than once in a program.B) Function definition cannot appear in any order.C) Functions cannot be distributed in many files.D) One function cannot be defined within another function definition.Answer: D

Page 36: Total c Prog Bits(450)

The parameters in a function call are ________.A) actual parameters.B) formal parameters.C) dummy parameters.D) optional.Answer: A

What does the following C-statement declare? int ( * f) (int * ) ; A) A function that takes an integer pointer as argument and returns an integer B) A function that takes an integer as argument and returns an integer pointer C) A pointer to a function that takes an integer pointer as argument and returns an integer.D) A function that takes an integer pointer as argument and returns a function pointerANSWER: C

What does the following program print?#include<stdio.h>void f(int *p, int *q){

p = q; *p = 2;

}int i = 0, j = 1;int main(){

f(&i, &j); printf("%d %d \n", i, j); getchar(); return 0;

}A) 2 2 B) 2 1 C) 0 1 D) 0 2ANSWER: D

What does the following fragment of C-program print?char c[] = "GATE2011";char *p =c;printf("%s", p + p[3] - p[1]);

A) GATE2011 B) E2011 C) 2011 D) 011ANSWER: C

Consider the following C program segment:char p[20];char *s = "string";int length = strlen(s);int i;for (i = 0; i < length; i++)

p[i] = s[length � i];printf("%s",p);The output of the program is

A) gnirts B) gnirtC) string D) no output is printed

Page 37: Total c Prog Bits(450)

ANSWER: DCommon Data Question for 25 & 26Consider the following C programint a, b, c = 0;void prtFun (void);int main (){

static int a = 1; /* line 1 */ prtFun(); a += 1; prtFun(); printf ( "\n %d %d " , a, b) ;

}void prtFun (void){

static int a = 2; /* line 2 */ int b = 1; a += ++b; printf (" \n %d %d " , a, b);

}What output will be generated by the given code segment?

A) 3 1 4 14 2

B) 4 2 6 1

6 1 C) 4 2

6 2 2 0

D) 3 15 25 2

ANSWER: CWhat output will be generated by the given code segment if:Line 1 is replaced by �auto int a = 1;Line 2 is replaced by �register int a = 2;

A) 3 1 4 1 4 2

B) 4 2 6 1 6 1

C) 4 2 6 2 2 0

D) 4 24 22 0

ANSWER: DWhat is printed by the following C program?int f(int x, int *py, int **ppz){

int y, z; **ppz += 1; z = **ppz; *py += 2; y = *py; x += 3; return x + y + z;

Page 38: Total c Prog Bits(450)

}void main(){

int c, *b, **a; c = 4; b = &c; a = &b; printf( "%d", f(c,b,a)); getchar();

}A) 18 B) 19 C) 21 D) 22ANSWER: B

What does the following fragment of C program print? char c[] = "GATE2011";

char *p = c; printf("%s", p + p[3] - p[1]);A) GATE2011B) E2011C) 2011D) 011ANSWER: C

The smallest element of an array's index is called its A) Lower bound.B) Upper bound.C) Range.D) Extraction.ANSWER: A

O(N)(linear time) is better than O(1) constant time.A) True B) FalseANSWER: B

For 'C' programming languageA) Constant expressions are evaluated at compileB) String constants can be concatenated at compile timeC) Size of array should be known at compile timeD) All of theseANSWER: D

What is the maximun number of dimensions an array in C may have?A) TwoB) EightC) TwentyD) Theoratically no limit. The only practical limits are memory size and compilersANSWER: D

If x is an array of interger, then the value of &x[i] is same asA) &x[i-1]+sizeof(int)B) x+sizeof(int)*iC) x+iD) none of theseANSWER: C

If S is an array of 80 characters, then the value assigned to S through the statement scanf("%s",S) with input 1 2 3 4 5 would beA) "12345"B) nothing since 12345 is an integerC) S is an illegal name for stringD) %s cannot be used for reading in values of SANSWER: A

Page 39: Total c Prog Bits(450)

Size of the array need not be specified, whenA) Initialization is a part of definitionB) It is a declaratrionC) It is a formal parameterD) All of theseANSWER: D

A one dimensional array A has indices 1....75.Each element is a string and takes up three memory words. The array is stored starting at location 1120 decimal. The starting address of A[49] isA) 1167B) 1164C) 1264D) 1169ANSWER: C

Minimum number of interchange needed to convert the array 89,19,40,14,17,12,10,2,5,7,11,6,9,70, into a heap with the maximum element at the root isA) 0B) 1C) 2D) 3ANSWER: C

Which of the following is an illegal array definition?A) Type COLOGNE:(LIME,PINE,MUSK,MENTHOL); var a:array[COLOGNE]of REAL;B) var a:array[REAL]of REAL;C) var a:array['A'..'Z']of REAL;D) var a:array[BOOLEAN]of REAL;ANSWER: B

#include<stdio.h>#include<stdarg.h>void fun1(int num, ...);void fun2(int num, ...);

int main(){

fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0;

}void fun1(int num, ...){

char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str);

}void fun2(int num, ...){

va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num);

}A) Dogs 12B) Cats 14C) Boys 13D) Apple 12ANSWER: A

#include<stdio.h>#include<stdarg.h>

Page 40: Total c Prog Bits(450)

fun(...);

int main(){

fun(3, 7, -11.2, 0.66); return 0;

}fun(...){

va_list ptr; int num; va_start(ptr, n); num = va_arg(ptr, int); printf("%d", num);

}A) Error: fun() needs return typeB) Error: ptr Lvalue requiredC) Error: Invalid declaration of fun(...)D) No errorANSWER: C

#include<stdio.h>#include<stdarg.h>void display(int num, ...);

int main(){

display(4, 'A', 'a', 'b', 'c'); return 0;

}void display(int num, ...){

char c; int j; va_list ptr; va_start(ptr, num); for(j=1; j<=num; j++) { c = va_arg(ptr, char); printf("%c", c); }

}A) Error: unknown variable ptrB) Error: Lvalue required for parameterC) No error and print A a b cD) No error and print 4 A a b cANSWER: C The value of a resistor creating thermal noise is doubled the noise power generated is therefore A) Halved B) Quadrupled C) UnchangedD) DoubledANSWER: C

De-emphasis circuit is usedA) After modulationB) Prior to modulationC) To de-emphasis low frequency component D) To de-emphasis high frequency component ANSWER: D

The capacity of a channel is A) Number of digits used in coding

Page 41: Total c Prog Bits(450)

B) Volume of information it can take C) Maximum rate of information transmissionD) Bandwidth required for informationANSWER: C

void main() { int const *p=5; printf("%d"' ++(*p)); }A) 6B) 5c) Garbage valueD) compilier ErrorANSWER: D

main(){static int var=5;printf("%d"'var--);if(var)main();

A) 1.55555B) 54321C) infinite loopD) NoneANSWER: B

main(){

char *p;printf("%d%d",size of(*p),size of(p));

A) 11B) 12C) 21D) 22ANSWER: B

main(){int c=--2;printf("c=%d",c);}

A) 1B) -2C) 2D) ErrorANSWER: B

#define int charmain(){inti=65;printf("size of(i)=%d",size of(i));}

A) size of(i)=2B) size(i)=1C) compiler errorD) NoneANSWER: B

main() {

char string[]="Helloworld"display(strings);}

Page 42: Total c Prog Bits(450)

void diaplay(char*string){printf("%s",string)}

A) compiler ErrorB) HelloworldC) can't sayD) NoneANSWER: A #define square(*)***

main(){

int i;i=64/squqre(4);printf("%d",i);}

A) 4B) 64C) 16D) NoneANSWER: B

The parameters in a function definition are _________.A) actual parameters.B) formal parameters.C) dummy parameters.D) optional.Answer: B

Recursive call results when ________.A) a function calls itself.B) a function1 calls another function, which in turn calls the function1.C) both 1 & 2.D) a function calls another function.Answer: C

The storage class allowed for parameters is _________.A) auto storage class.B) static storage class.C) extern storage class.D) register storage class.Answer: C

Functions have ________.112-C ProgrammingA) file scope.B) local scope.C) block scope.D) function scope.Answer: A

The function floor(x) in math.h __________.A) returns the value rounded down to the next lower integer.B) returns the value rounded up to the next higher integer.C) the next lower value.D) the next higher value.Answer: A

The function strcpy(s1,s2) in string.h __________.A) copies s1 to s2.B) copies s2 to s1.C) appends s1 to end of s2.D) appends s2 to end of s1.Answer: B

The function strcat(s1,s2) in string.h __________.A) copies s1 to s2.

Page 43: Total c Prog Bits(450)

B) copies s2 to s1.C) appends s1 to end of s2.D) appends s2 to end of s1.Answer: D

The function strcmp(s1,s2) returns zero _________.A) if s1 is lexicographically less than s2.B) if s1 is lexicographically greater than s2.C) if both s1 ans s2 are equal.D) if s1 is empty string.Answer: C

What will be the output of following program ? #include<stdio.h> int main( ) { float a=5,b=2; int c,d; c =a%d; d =a/2; printf("%d\n",d); return 0; } A) 3B) 2C) ErrorD) None of aboveANSWER: C

What is error in following declaration?struct outer{int a;struct inner{char c;};};

A) Nesting of structure is not allowed in c.B) It is necessary to initialize the member variable.C) Inner structure must have name.D) Outer structure must have name.ANSWER: C

What will be the output of program ? #include<stdio.h> int main( ) { printf("nn /n/n nn/n"); return 0; } A) NothingB) nn /n/n nnC) nn /n/nD) ErrorANSWER: B

What will be the output of program ? #include<stdio.h> int main( ) { int a,b; printf("Enter two values of a and b"); scanf("%d%d",&a,&b); printf("a=%d b=%d"a,b); return 0;

Page 44: Total c Prog Bits(450)

}A) a = 0 b = 0B) a = 1 b = 1C) Values you enteredD) None of aboveANSWER: C

A character variable can at a time store ?A) 1 characterB) 8 characterC) 254 characterD) None of aboveANSWER: A

The maximum value that an integer constant can have is ?A) -32767B) 32767C) 1.7014e + 38D) -1.7014e + 38ANSWER: B

What will be output if you will compile and execute the following c code?

void main(){int array[]={10,20,30,40};printf("%d",-2[array]); }

(A) -60(B) -30(C) 60(D) Garbage valueANSWER: B

Which of the following is false in C ?A) Keywords cannot be used as variable namesB) Variable names can contain a digitC) Variable names do not contain a blank spaceD) Capital letters can be used in variable namesANSWER: A

On which if the following operator can % operator NOT be used ?A) int variableB) float variableC) int constantD) All of above

What is the output of the following code?

#includevoid main(){int s=0;while(s++<10)# define a 10main(){printf("%d..",a);foo();printf("%d",a);}void foo(){#undef a#define a 50

A) 10..10

Page 45: Total c Prog Bits(450)

B) 10..50C) ERRORD) 0ANSWER: C

void main(){int a=10,b=20;char x=1,y=0;if(a,b,x,y){printf("EXAM");}}What is the output?

A) XAM is printedB) exam is printedC) Compiler ErrorD) Nothing is printedANSWER: C

int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};What value does testarray[2][1][0] in the sample code above contain?

A) 11B) 7C) 5D) 9ANSWER: A

The function toupper(ch) in ctype.h _________.A) returns the upper case alphabet of ch.B) returns the lower case alphabet of ch.C) returns the upper case if ch is lower case, and lower case if ch is upper case.D) is a user-defined function.Answer: A

The function tolower(ch) in ctype.h _________.A) returns the upper case alphabet of ch.B) returns the lower case alphabet of ch.C) returns the upper case if ch is lower case, and lower case if ch is upper case.D) is a user-defined function.Answer: B

Which of the following would compute the square of x in C?A) pow(2,x);B) pow(x,2);C) x**2;D) powe(x,2);112-C ProgrammingAnswer: B

All standard C library <math.h> functions return what data type?A) decimal.B) float.C) double.D) int.Answer: C

When a function is recursively called all automatic variables are _________.A) stored in stack.B) stored in queue.C) stored in array.D) stored in linked list.Answer: A

Page 46: Total c Prog Bits(450)

What is the output of the following code?main(){printf(�%d\n�,sum(5));}int sum(int n){if(n<1) return n;else return(n+sum(n-1));}

A) 10.B) 16.C) 14.D) 15.Answer: D

Pointers are supported in __________.A) FORTRAN.B) PASCAL.C) C.D) both options 2 and 3 .Answer: D

Pointer variable may be assigned ______.A) an address value represented in hexadecimal.B) an address value represented in octal.C) the address of another variable .D) an address value represented in binary.Answer: C

The operators exclusively used in connection with pointers are________.A) * and /.B) & and *.C) & and |.D) � and >.Answer: B112-C Programming

Identify the wrong declaration statement.A) int *p, a=10.B) int a=10,*p=&a.C) int *p=&a, =10 .D) options 1 and 2.Answer: C

Identify the invalid expression , int num=15, *p=&num.A) *num.B) *(&num).C) *&*&num.D) **&p.Answer: A

How does the compiler differentiate address of operator from bitwise AND operator?A) by using the number of operands and position of operands.B) by seeing the declaration.C) both options 1 and 2.D) by using the value of the operand.Answer: A

The address of operator returns _________.A) the address of its operand.B) 1 value.C) both options 1 and 2.D) r value.Answer: A

Pointer variable may be initialized using _________.A) static memory allocation.

Page 47: Total c Prog Bits(450)

B) dynamic memory allocation.C) both options (a) and (b).D) a positive integer.Answer: C

The number of arguments used in malloc ( ) is _________.A) 0.B) 1.C) 2.D) 3.Answer: BThe function used for dynamic deallocation of memory is __________.A) destroy ( ).B) delete ( ).C) free ( ).D) remove ( ).Answer: C

The pointers can be used to achieve _________/A) call by function.B) call by reference.C) call by name.112-C ProgrammingD) call by procedure.Answer: B

Identify the correct statement for given expressionFloat fnum [10], *fptr = fnum.

A) fnum is pointer variable.B) fnum is a fixed address and not a variable.C) fnum is an array variable.D) fnum is an address that can be modified.Answer: B

Given int a[5];how to declare array in the function definition if the function call is

sort(a)?A) sort(int *a).B) sort(int a[5]).C) both options (a) and (b).D) sort(int a).Answer: C

Given int *p1,**p2,***p3,v=25;How to obtain the value of v using pointer variable?

A) *p1.B) **p2.C) ***p3.D) all the above.Answer: D

The declaration float *a[5];is ________.A) an ordinary array.B) a pointer to an array.C) an array of pointers.D) pointer to an array.Answer: C

Given char *p=�ANSI C�; identify the expression returning the value C.A) strcpy(t[0],�BASIC�);B) t[0]=�JAVA�;C) both options 1 and 2.D) both options 2 and 3.Answer: B

Given char *p=�ANSI C�; identify the expression returning the value C.

(A) strcpy(t[0],�BASIC�);

Page 48: Total c Prog Bits(450)

(B) t[0]=�JAVA�;(C) both options 1 and 2.(D) both options 2 and 3.Answer: B

The arguments argc in main( ) counts __________.

A) the number of command line strings including the execution command.B) the number of command line strings excluding the execution command.C) the number of lines in a program.D) the number of characters in a program.Answer: A

In the declaration double (*pf)( ); __________.

A) pf is a pointer to a function.B) pf is a function returning pointer.C) pf is a pointer to array.D) pf is an array of pointers.112-C ProgrammingAnswer: A

The operation that can be performed on pointers are __________.

A) addition and subtraction of a pointer and an integer.B) assignment of pointer using pointer expression.C) assignment of the value 0 to a pointer.D) all the above.Answer: D

When applied to a variable, what does the unary �&� operator yield?

A) the variable�s value.B) the variable�s address.C) the variable�s format.D) the variable�s right value.Answer: B

Which of the following is the most accurate statement about runtime memory?

A) memory is allocated by using malloc ( ).B) memory is freed by a garbage collector.C) allocated memory can be freed by calling free ( ).D) Both options 1 and 3.Answer: D

char *ptr; char string [ ]=�project�; ptr +=(ptr+5); What string does ptr contain in the sample code above?

A) ct.B) ject.C) object.D) Unknown. This code is incorrect.Answer: D

Scrutinize the following code in C. Char fruit [ ]=�Orange�; Char *ptr;

Page 49: Total c Prog Bits(450)

ptr =fruit; What will be the output for the following expression?

A) r.B) a.C) n.D) none.Answer: B

main ( ){int a=5,*ptr;ptr=&a;printf (�%d�,++*ptr);}The output might be _________.

A) 6.112-C ProgrammingB) 5.C) 0.D) none.Answer: A

main ( ){Char x [25], y [25],*p=y;Strcpy (x,� BIRTHDAY�);Strcpy (y,� HAPPY�);P=x;Strcpy (x, �MOTHER�);*p=� D�;printf (�p=%s\n�, p);}What will be the output when the sample code is executed?

A) p=DOTHERDAY.B) p=MOTHERDAY.C) p=DOTHER.D) p=DIRTHDAY.Answer: C

Which statement correctly defines a character string with a length of 4 plus 1 for the

terminating NUL?

A) char string[ ];.B) char* string[ ];.C) char * string[5];.D) char string[5];.Answer: D

int y[4] = {6,7,8,9};int *ptr = y+2;printf(�%d\n�, ptr[1]);What is printed when the sample code above is executed?

A) 7.B) 8.C) 9.D) The code will not compile.

Page 50: Total c Prog Bits(450)

Answer: C What memory function should be used to allocate memory in which all bit

s are initialized to 0?

A) calloc.B) malloc.C) alloc.D) memalloc.Answer: A

int *const size = 10;If the address of size is 3024, then size ++ is ________.

A) 11.112-C ProgrammingB) 3025.C) 3026.D) invalid.Answer: D

The amount of memory to be allocated for the following array of pointersshort *p[4]; is _________.

A) no memory.B) 4 bytes.C) 6 bytes.D) 16 bytes.Answer: D

int x = 1;int *ptr=malloc(sizeof(int));ptr=&x;x+2;*ptr+3;Is there anything wrong with the above code?

A) No ,x will be set to 2.B) No, x will be set to 3.C) Yes, There will be a memory overwrite.D) Yes, There will be a memory leak.Answer: C

main ( ){int a[4][2];int b=0,x;int i,y;for (i=0; i<4; i++)for(y=0;y<2;y++)a[i][y] = b++x=*(*(a+2)-1);}What is the value of x in the above samples?

A) 2.B) 3.C) 4.D) 5.Answer: B

Page 51: Total c Prog Bits(450)

float (*f[5] ( ) ); This declaration represents _________.

A) pointer to function returning array of float.B) pointer to array of pointer to function returning float.C) array of pointers to function returning array of float.D) array of pointers to function returning float.Answer: D

float (*(*f[5]) ( ) )[10]; This declaration represents _________.

A) array[5] of function returning a pointer to array[10] of float.112-C ProgrammingB) array of pointer returning pointer to array[10] of float.C) array[5] of pointer to a function returning a pointer to array[10] of float.d) none.Answer: C

int a=1; b=2; c=3; *pointer;pointer=&c;a=c/*pointer;b=c;printf(�a=%d b=%d�,a,b);What will be the output?

A) a=1 b=3.B) a=3 b=3.C) 2.D) Error.Answer: D

Which are valid?

A) Pointers can be added.B) pointers can be subtracted.C) integers can be added to pointers.D) Both 1 and 2. all correct.\Answer: A

p and q are pointers to the same type of data items.Which of these are valid?

A) *(p+q).B) *(p-q).C) *p-*q.D) none of the above.Answer: C

int *ifloat *f;char *c;Which are valid castings?

A) (int*)&c.B) (float*)&c.C) (char*)&i.D) all of the above.Answer: A

What is the result of the expression or the following declaration?int A [ ]={1,2,3,4,5};

Page 52: Total c Prog Bits(450)

*A+1-*A+3

A) 2.B) -2.C) 4.D) none of the above.Answer: C

Structure is a __________.112-C Programming

A) scalar data type.B) derived data type.C) both options 1 and 2.D) primitive data type.Answer: B

Structure is a data type in which ________.

A) each element must have the same data type.B) each element must have pointer type only.C) each element may have different data type.D) no element is defined.Answer: C

C provides a facility for user defined data type using ________.

A) pointer.B) function.C) structure.D) array.Answer: B

Structure declaration __________.

A) describes the prototype.B) creates structure variable.C) defines the structure function.D) is not necessary.Answer: A

A structure ________.

A) can be read as a single entity.B) cannot be read s a single entity.C) can be displayed as a single entity.D) has a member variable that cannot be individually read.Answer: B

A structure can have ___________.

a) pointers as its members.b) scalar data type as its members.c) structure as its member.d) all the above.Answer: C

In a structure definition, __________.

A) initialization of structure members are possible.B) initialization of array of structures are possible.

Page 53: Total c Prog Bits(450)

C) both options 1 and 2.D) initialization of array of structures are not possible.Answer: C

The operator exclusively used with pointer to structure is _______.

A) ..B) ? .C) [ ].D) *112-C ProgrammingAnswer: B

If one or more members of a structure is created ,then the structure is known as

____________.

A) nested structure.B) invalid structure.C) self-referential structure.D) unstructured structure.Answer: A

The changes made in the members of a structure are not available in the calling function

if __________.

A) pointer to structure is passed as argument.B) the members other then pointer type are passed as arguments.C) structure variable passed as argument.D) both options 1 and 2.Answer: A

#include<stdio.h>#define a 10main(){#define a 50printf("%d",a);}

A) 50B) 10C) compile ErrorD) NoneANSWER: A

#define clrscr() 100main(){clrscr();

printf("%d/n");clrscr();

A) 0B) 1C) 100D) NoneANSWER: C main()

{int i=1;j=2;switch(i){

Page 54: Total c Prog Bits(450)

case i:printf("GOOD");break;case j;printf("BAD");break;}}

a) Goodb) Badc) GOOD BadD) ErrorANSWER: D

main(){int i=0;

for(;i++;prntf("%d",i));printf("%d",i);

}A) 1B) 11C) 12D) ErrorANSWER: A

main() {

extern int i;i=20;printf("%d",size of(i));}

A) 20B) 2C) compile ErrorD) Linear ErrorANSWER: D

main(){int i=0;j=0;

if(i&&j++)printf("%d..%d",i++,j);printf("%d..%d",i,j);}

A) 0..1B) 1..0C) 0..0D) 1..1ANSWER: D

void main(){static int i=5;if(--i)

{main();printf("%d",i);}}

A) 54321B) 0000C) infiniteloopD) NoneANSWER: B

#includemain(){

Page 55: Total c Prog Bits(450)

register i=5;char j[]=("hello");printf("%s%d",j,i);}

A) Hello 5B) Hello garbage valueC) ErrorD) NoneANSWER: A

main(){int i=abc(10);

printf("%d\n",--i);}

int abc(int i){return(i++);}

A) 10B) 9C) 11D) NoneANSWER: B

void main(){static int i=i++,j=j++,k=k++;printf("%d%d%d",i,j,k);}

A) 111B) 000C) Garbage valueD) ErrorANSWER: A

#define pnod(a,b) a*bmain(){int x=3,y=4;printf("%d,pnod(x+2,y-1));}

A) 15B) 10C) 12D) 11ANSWER: B

main(){char p[]="%d\n";p[1]='c';printf(p,65);

A) 65B) Cc) AD) ErrorANSWER: C

What is the return value of f( p,p) if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value. int f( int & x, int c) { c= c- 1;

Page 56: Total c Prog Bits(450)

If( c== 0) return 1; X= x+ 1; return f (x,c) * x;

} A) 3024 B) 6561 C) 55440 D) 161051ANSWER: c

What will be the output of the following program ?#includevoid main(){ int a = 2;switch(a){ case 1:printf("goodbye"); break;case 2:continue;case 3:printf("bye");}}

A) errorB) goodbyeC) byeD) byegoodbyeANSWER: A3. int i = 4;

switch (i){default: ;case 3:i += 5;if ( i == 8) {i++;if (i == 9) break;i *= 2; } i -= 4; break; case 8:i += 5;break;}printf("i = %d\n", i);

What will the output of the sample code above be?A) i = 5B) i = 8C) i = 9D) i = 10ANSWER: A

Identify the wrong statement.

A) Structure variable can be passed as argument.B) Pointer to structure can be passed as argument.C) Member variable of a structure can be passed as argument.D) none of the above.Answer: D

Page 57: Total c Prog Bits(450)

Structure is used to implement the ________ data structure .

A) stack.B) queue.C) tree.d) all the above .Answer: D

A bit field is __________.

A) A pointer variable in a structure.B) One bit or set of adjacent bits within a word.C) A pointer variable in a union.D) Not used in C.Answer: B

struct car{int speed;Char type [10];} vehicle;struct car *ptr;ptr=&vehicle;Referring to the sample code above,which of the following will make the

speed equal to200?

A) (*ptr).speed=200;.B) (*ptr)?speed=200;.C) *ptr.speed=200;.D) &ptr.speed.112-C ProgrammingAnswer: A

File is ___________.

A) a data type.B) a region of storage .C) both option 1 and 2.D) a variable.Answer: B

The way to access file are accessed through______.

A) by using library functions.B) by using system calls.C) both options 1 and 2 .D) to use a linker.Answer: C

Low level files are accessed through ________.

A) system calls.B) library functions.C) linker.D) loader.Answer: A

C supports _________.

A high level files.

Page 58: Total c Prog Bits(450)

B low level files.C both options 1 and 2.C executable files only.Answer: C

I/O stream can be _________.

A a text steam.B a binary stream.C both options 1 and 2.D an I/O operation.Answer: C

File opening is ___________.

A a default action in file processing.B an action of connecting a program to a file.C not necessary.D not using any library function.Answer: B

FILE defined in stdio.h is ____________.

A a region of storage.B a data type.C not a data type.D a variable.Answer: B

A file pointer is ___________.

A a stream pointer.B a buffer pointer.112-C ProgrammingC a pointer to FILE data type.D all the above.Answer: D

If fopen ( ) fails, it returns __________.A -1.B NULL.C 1.D the file pointer.Answer: B

The action of connecting a program to a file is obtained by using __________.

A fclose ( ).B delete( ).C fdisconnect( ).D clear ( ).Answer: A

The value returned by fclose( ), if an error occurs is _______.

A 0.B 1.C EOF.D -1.Answer: C

Page 59: Total c Prog Bits(450)

The function(s) used for reading a character from a file is (are) __________.

a. getc( ).b. getc.c. both options 1 and 2.d. getchar( ).Answer: C

The function used for random access of a file is __________.

A fseek( ).B ftell( ).C search( ).D rewind( ).Answer: A

What is the value of origin used in fseek(fptr,position,origin);? To represent end of file.

A 0.B 1.C 2.D START.Answer: A

If an error occurs, the function fseek( ) returns __________.

A non-zero.B zero.C OK.D READY.Answer: B112-C Programming

The value returned by ftell( ) if an error occurs is ___________.

A -1.B 0.C Positive value.D MIN_INT.Answer: A

The function used for writing to binary streams is _____________.

A write ( ).B fwrite( ).C fprintf( ).D all the above.Answer: B

Identify the functions for in-memory format conversions ___________.

A realloc( ).B sprintf( ).C sscanf( ).D both options 2 and 3.Answer: D

The value of string after executing the following statements isint x=25; char string[5];sprintf(string. � %d�, x);

Page 60: Total c Prog Bits(450)

A �25�.B 25.C TWO FIVE.D 25000.Answer: A

Identify the correct statement.A # include �filename�.B # include <filename>.C both options 1 and 2.D # include filename.Answer: C

The following line a program # represents ______.

A an invalid code.B a null code.C a comment.D a page number.Answer: B

Macros _________.

A can be recursively defined.B cannot be recursively defined.C cannot be defined.D are not preprocessor facility.Answer: B

Identify the token passing operator.

A +.112-C ProgrammingB ++.C #.D ##.Answer: D

The directive(s) used in conditional compilation is (are) __.

A #if.B #elif.C #else.D all the above.Answer: D

Functions may use_______.

A varying number of parameters.B fixed number of parameters.C no argument.D at most five arguments.Answer: A

Identify the trigraph sequence for #

A ??/.B ??=.C ??�.D ??!.Answer: B

Page 61: Total c Prog Bits(450)

Which of the following is valid for opening a read-only ASCII file?

A fileOpen (filenm, �read�);.B fopen (filenm, �r�);.C fileOpen (filenm, �r�);.D fopen (filenm, �read�);.Answer: B

What are two predefined FILE pointers in C?

A stdout and stderr.B console and error.C stdout and stdio.D stdio and stderr.Answer: A

Which of the following is NOT a valid preprocessor directive?

A #if.B #line.C #elseif.D #pragma.Answer: C

The function used to position the file pointer in C is __________.

A seekg( ).B fseekg( ).C fseek( ).D fileseek( ).Answer: C112-C Programming

Which of the following function returns calendar time to local time?

A Gmtime.B ctime.C strtime.D asctime.Answer: B

Which ANSI C standard function could be used to sort a string array?

A Qsort.B sort.C assort.D bsort.Answer: A

Which is the fundamental data type is used to implement the enum data type?

A Char.B int.C float.D double.Answer: B

#define max(a,b) (a>b?b:a)#define squre(x) x*x

Page 62: Total c Prog Bits(450)

int i=2,j=3,k=1;printf(�%d %d�, max(i,j), squre(k) );What is the output generated by the above code?

A 3 2.B 3 1.C 2 1.D 2 2.Answer: C

What is the value of CAR in the following enumeration?enum transport{SCOOTER=1, BUS=4, CAR, TRAIN=8};

A 0.B 5.C 7.D 4.Answer: B

What is the value of LOTUS in the following enumeration?enum symbol{HAND, SUN, LOTUS, UMBRELLA};

A 0.B 3.112-C ProgrammingC 2.D None of the above.Answer: C

What is the output of the following code?enum fruits{APPLE=1, ORANGE=1, GRAPES=3, PINEAPPLE};printf (�%d�,ORANGE);

A Compilation error.B Execution error.C 2.D 1.Answer: D

What will be the output for the following code?enum control{On, off, neutral};PRINTF (�%d�, off);

A Compilation error.B Execution error.C 5.D 1.Answer: A

If there is a need to see output as soon as possible, which of the foll

Page 63: Total c Prog Bits(450)

owing will force theoutput from the buffer into the output stream?

A write ( ).B output ( ).C flush ( ).D fflush ( ).Answer: D

What will be the value of j in the following code?

A 24.B 25.C 28.D 32.Answer: B

The qualifier const __________.

A defines a constant name.B keeps the value of a variable constant during execution of a program.C both options 1 and 2.D does not keep value of variable constant.Answer: B

The keyword used to represent a structure data type is______.A sructure.112-C ProgrammingB struct.C struc.D structr.Answer: B

After the execution of the statement int x; the value of x is

A 0.B undefined.C 1.D -1.Answer: B

After the execution of the statement int x; the value of x isA) 0.B) undefined.C) 1.D) -1.Answer: B

int z, x=5, y=-10, a=4, b=2;z=x++ - --y * b / a;What number will z in the sample code above contain?

A) 5B) 6C) 10D) 11Answer: C With every use of a memory allocation function, what function should be used to release

allocated memory which is no longer needed?A) unalloc()B) dealloc()C) release()D) free()

Page 64: Total c Prog Bits(450)

Answer: Dvoid *ptr;myStruct myArray[10];ptr = myArray;Which of the following is the correct way to increment the variable "ptr

"?A) ptr = ptr + sizeof(myStruct);B) ++(int*)ptr;C) ptr = ptr + sizeof(myArray);D) increment(ptr);Answer: A

"My salary was increased by 15%!"Select the statement which will EXACTLY reproduce the line of text above

.A) printf("\"My salary was increased by 15/%\!\"\n");B) printf("My salary was increased by 15%!\n");C) printf("My salary was increased by 15'%'!\n");D) printf("\"My salary was increased by 15%%!\"\n");Answer: D

What is a difference between a declaration and a definition of a variable?A) Both can occur multiple times, but a declaration must occur first.B) There is no difference between them.C) A definition occurs once, but a declaration may occur many times.D) A declaration occurs once, but a definition may occur many times.112-C ProgrammingAnswer: D206. int a=10, b;

b = a++ + ++a;printf(�%d,%d,%d,%d�,b,a++,a,++a);what will be the output when following code is executed

A) 12,10,11,13.B) 22,10,11,13.C) 22,11,11,11.D) 22,13,13,13.Answer: D

#define MAX_NUM 15Referring to the sample above, what is MAX_NUM?

A) MAX_NUM is an integer variable.B) MAX_NUM is a linker constant.C) MAX_NUM is a precompiler constant.D) MAX_NUM is a preprocessor macro.Answer: D

int x = 2 * 3 + 4 * 5;What value will x contain in the sample code above?

A) 22.B) 26.C) 46.D) 50.Answer: B

int var1;If a variable has been declared with file scope, as above, can it safely

be accessedglobally from another file?

A) Yes; it can be referenced through the register specifier.B) No; it would have to have been initially declared as a static variable.C) No; it would need to have been initially declared using the global keywordD) Yes; it can be referenced through the publish specifier.Answer: C

Page 65: Total c Prog Bits(450)

C is a ___________ language.A) Machine.B) Procedural.C) Assembly .D) Object-oriented.Answer: B

In a C expression, how is a logical AND represented?A) @@ .B) || .B) AND.B) && .Answer: D

How do printf()'s format specifiers %e and %f differ in their treatment of floating-point112-C Programming

numbers?A) %e always displays an argument of type double in engineering notation; %f always

displays an argument of type double in decimal notation.B) %e expects a corresponding argument of type double; %f expects a corresponding

argument of type float.C) %e displays a double in engineering notation if the number is very small or very large.

Otherwise, it behaves like %f and displays the number in decimal notation.D) %e displays an argument of type double with trailing zeros; %f never displays trailing

zeros.Answer: A

Which one of the following will read a character from the keyboard and will store it in

the variable c?A) c = getc();B) getc( &c );C) c = getchar( stdin );D) c = getchar();Answer: D

#include<stdio.h>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?

A) It will not compile.B) It will print out: i=9.C) It will print out: i=10.D) It will loop indefinitely.Answer: D

Which one of the following C operators is right associative?A) = .B) , .c) [] .

Page 66: Total c Prog Bits(450)

D) ^ .Answer: A

What does the "auto" specifier do?A) It automatically initializes a variable to 0;B) It indicates that a variable's memory will automatically be preserved.112-C ProgrammingC) It automatically increments the variable when used.D) It automatically initializes a variable to NULL.Answer: A

How do you include a system header file called sysheader.h in a C source file?A) include <sysheader.h> .B) #incl "sysheader.h" .C) #includefile <sysheader>.D) #include sysheader.h .Answer: B

According to the Standard C specification, what are the respective minimum sizes (in

bytes) of the following three data types: short; int; and long?A) 1, 2, 2 .B) 1, 2, 4.C) 1, 2, 8.D) 2, 2, 4.Answer: A

penny = onenickel = fivedime = tenquarter = twenty-fiveHow is enum used to define the values of the American coins listed above

?A) enum coin {(penny,1), (nickel,5), (dime,10), (quarter,25)};B) enum coin ({penny,1}, {nickel,5}, {dime,10}, {quarter,25});C) enum coin {penny=1,nickel=5,dime=10,quarter=25};D) enum coin (penny=1,nickel=5,dime=10,quarter=25);Answer: D

char txt [20] = "Hello world!\0";How many bytes are allocated by the definition above?

A) 11 bytes.B) 12 bytes.C) 13 bytes.D) 20 bytes.Answer: C

int i = 4;int x = 6;double z;z = x / i;printf(�z=% .2f\n�, z);What will print when the sample code above is executed?

A) z=0.00.B) z=1.00.C) z=1.50.D) z=2.00 .Answer: D

Which one of the following variable names is NOT valid?112-C ProgrammingA) go_cart.B) Go4it .C) 4season.D) 4.Answer: B

How is a variable accessed from another file?

Page 67: Total c Prog Bits(450)

A) The global variable is referenced via the extern specifier.B) The global variable is referenced via the auto specifier.C) The global variable is referenced via the global specifier.D) The global variable is referenced via the pointer specifier.Answer: C

When applied to a variable, what does the unary "&" operator yield?A) The variable's value.B) The variable's binary form.C) The variable's address.D) The variable's format.Answer: A

long factorial (long x){return x * factorial(x - 1);}With what do you replace the ???? to make the function shown above retur

n the correct answer?

A) if (x == 0) return ;B) return 1;C) if (x >= 2) return 2;D) if (x <= 1) return 1;ANSWER: D int i = 4;

switch (i){default: ;case 3:i += 5;if ( i == 8) {i++;if (i == 9) break;i *= 2; } i -= 4; break; case 8:i += 5;break;}printf("i = %d\n", i);What will the output of the sample code above be?

A) i = 5B) i = 8C) i = 9D) i = 10ANSWER: A #include

void func(){int x = 0;static int y = 0;x++; y++;printf( "%d -- %d\n", x, y );}int main(){func();func();return 0;}

Page 68: Total c Prog Bits(450)

What will the code above print when it is executed?A) 1 -- 11 -- 1B) 1 -- 12 -- 1C) 1 -- 12 -- 2D) 1 -- 11 � 2ANSWER: D What will be the value of `a` after the following code is executed

#define square(x) x*xa = square(2+3)

A) 25B) 13C) 11D) 0ANSWER: C

#includevoid main(){int a = 36, b = 9;printf("%d",a>>a/b-2);}

A) 9B) 7C) 5D) none of theseANSWER: A

What will be the output of the following statements ?int a = 4, b = 7,c; c = a = = b; printf("%i",c);

A) 0B) errorC) 1D) garbage valueANSWER: A

What will be the output of the following statements ?int a = 5, b = 2, c = 10, i = a>bvoid main(){ printf("hello"); main(); }

A) 1B) 2C) infinite number of timesD) none of theseANSWER: c

What will be the output of the following statements ?int x[4] = {1,2,3}; printf("%d %d %D",x[3],x[2],x[1]);

A) 03%DB) 000C) 032D) 321ANSWER: c What will be the output of following code ? #include<stdio.h> void main( ) { char suite =3; switch(suite) {

Page 69: Total c Prog Bits(450)

case 1: printf("ALL QUIZ"); case 2: printf("All quiz is great"); default: printf("All quiz contains MCQs"); } printf("Are you like All quiz ?"); } A) ALL QUIZB) All quiz is greatC) All quiz contains MCQsD) All quiz is great Are you like Al quiz ?ANSWER: D

What will be the output of following code ? void main( ) { int c=3; switch(c) { case '3': printf("Hi"); break; case 3: printf("Hello"); break; default: printf("How r u ?"); } }

A) HiB) HelloC) How r u ?D) None of aboveANSWER: B

What will be the output of following program ? void main( ) { int 1=3; switch(i) { case 0: printf("I am here"); case 1+0: printf("I m in second case"); case 4/2: printf("I m in third case"); case 8%5: printf("Good bye"); } }

A) All case statements will be executedB) I am hereC) Good byeD) I am in third case

Page 70: Total c Prog Bits(450)

ANSWER: C What will be the output of following ?

void main( ) { int suite =1; switch(suite); { case 0: printf("Its morning time"); case 1: printf("Its evening time"); } }

A) ErrorB) Its morning timeC) Its evening timeD) None of aboveANSWER: A

What will be the output of following program ? #include<stdio.h> int main( ) { int i=2,j=3,k,l; float a,b; k = i/j * j; l = j/i * j; a = i/j * j; b = j/i * i; printf("%d %d%f%f\n",k,l,a,b); return 0; }

A) 3, 0, 0, 0B) 0, 3, 0.000000, 2.000000C) 0,0,0,0D) ErrorANSWER: B

What will be the output of following program ? #incllude<stdio.h> int main( ) { int a,b; a = -3 - - 25; b = -3 - - (-3); printf("a=%d b=%d\n",a,b); return 0; }A) a = 22 b = -6B) a = -6 b = 22C) a = 3 b = 3D) No OutputANSWER: A

What will be the output of following program ? #include<stdio.h> int main( ) { float a=5,b=2; int c,d; c =a%d;

Page 71: Total c Prog Bits(450)

d =a/2; printf("%d\n",d); return 0; } A) 3B) 2C) ErrorD) None of aboveANSWER: C

What will be the output of program ? #include<stdio.h> int main( ) { printf("nn /n/n nn/n"); return 0; } A) NothingB) nn /n/n nnC) nn /n/nD) ErrorANSWER: B

What will be the output of program ? #include<stdio.h> int main( ) { int a,b; printf("Enter two values of a and b"); scanf("%d%d",&a,&b); printf("a=%d b=%d"a,b); return 0; }A) a = 0 b = 0B) a = 1 b = 1C) Values you enteredD) None of aboveANSWER: C

A character variable can at a time store ?A) 1 characterB) 8 characterC) 254 characterD) None of aboveANSWER: A

The maximum value that an integer constant can have is ?A) -32767B) 32767C) 1.7014e + 38D) -1.7014e + 38ANSWER: B

Which of the following is false in C ?A) Keywords cannot be used as variable namesB) Variable names can contain a digitC) Variable names do not contain a blank spaceD) Capital letters can be used in variable namesANSWER: A

On which if the following operator can % operator NOT be used ?A) int variableB) float variableC) int constantD) All of above

What is the output of the following code?

Page 72: Total c Prog Bits(450)

#includevoid main(){int s=0;while(s++<10)# define a 10main(){printf("%d..",a);foo();printf("%d",a);}void foo(){#undef a#define a 50

A) 10..10B) 10..50C) ERRORD) 0ANSWER: C

void main(){int a=10,b=20;char x=1,y=0;if(a,b,x,y){printf("EXAM");}}What is the output?

A) XAM is printedB) exam is printedC) Compiler ErrorD) Nothing is printedANSWER: C

int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};What value does testarray[2][1][0] in the sample code above contain?

A) 11B) 7C) 5D) 9ANSWER: A

Which one of the following is NOT a valid identifier?A) __ident.B) auto.C) bigNumber.D) g42277.Answer: C

A character variable can at a time store__________.A) 1 character.B) 8 characters.C) 254 characters.D) 22 characters.Answer: B

An integer constant in C must have ___________.A) At least one digit.B) At least one decimal point.

Page 73: Total c Prog Bits(450)

C) A comma along with digits.D) Digits separated by commas.Answer: A

The break statement is used to exit from_________.A) An if statement.B) A for loop.C) A program.D) The main() function.Answer: A

BCPL was developed in the year ___________.A) 1967.B) 1964.C) 1962.D) 1960.112-C ProgrammingAnswer: A

_______ convert from high-level language to machine languageA) Compiler.B) Interpreter.C) Assembler.D) Loader.Answer: A

Which of the following is not a rule for constructing integer constant.A) An integer constant must have atleast one digitB) It must have a decimal pointC) If no sign precedes an integer constant, it is assumed to be positive.D) No commas, or blanks are allowed within an integer constant.Answer: A

Which of the following is not a character constantA) �A�.B) �5�.C) �@�.D) Raju .Answer: B

Which of the following is not correct?A) An arithmetic operation between an integer and integer yields an integer result.B) An operation between real and real yield a integerC) An operation between integer and real yields a real resultD) Integer is first promoted to real and then operation is performed.Answer: D

The meaning of the expression x<=y is_____________.A) X is equal to y.B) X is not equal to y.C) X is greater than or equal to y.D) X is less than or equal to y .Answer: B

Which of the following expression is correct?A) expression1? expression2: expression3.B) expression1:expression2?expression3.C) expression1*expression2?expression3.D) expression1:expression2/expression3.Answer: D

What will be the output of the following?#include<stdio.h>Void main(){Int x;X=5;X=10;Printf(�x=%d�,x);

Page 74: Total c Prog Bits(450)

}112-C ProgrammingA) 5.B) 10 .C) 15.D) 20.Answer: A

What is the result of the following expression: i=2*3/4+4/4+8-2+5/8?A) 5.B) 8 .C) 10.D) 15.Answer: B

What is the output of the following?#include<stdio.h>main(){int a=300,b,c;if(a>=400){b=300;}c=200;printf(�%d%d�,b,c);}

A) 300.B) 200.C) 12803200.D) 100.Answer: B

What is the output of the following program?#include<stdio.h>void main(){int x=3, y=5;if(x==3)printf(�%d�,x);elseprintf(�%d�,y);}

A) 3.B) 2020.C) 5.D) 222.Answer: C

Predict the output or error(s) for the following:112-C Programmingvoid main(){int const * p=5;printf("%d",++(*p));}

A) 5.B) Compiler error: Cannot modify a constant value.C) Garbage value.D) 1248.Answer: C

What will be the output of the following program?main(){static int var = 5;printf("%d ",var--);

Page 75: Total c Prog Bits(450)

if(var)main();}

A) 5.B) 5 4 3 2 1.C) 3 2 3.D) Compiler Error.Answer: B

What will be the output for the following code?enum control{On, off, neutral};PRINTF (�%d�, off);

A) Compilation errorB) Execution errorC) 5D) 1Answer: A

Predict the output of the following program.main(){extern int i;i=20;printf("%d",i);}

A) 20.B) Compiler Error.C) Linker Error.D) Garbage value.Answer: A112-C Programming

Which of the following is the correct output for the program given below?

#include<stdio.h>void main(){int i=5;while(i-- >= 0) printf(�%d�,i);i=5;while(i-- >=0) printf(�%i�,i);while(i-- >=0) printf(�%d�, i);}

A) 4 3 2 1 0 -1 4 3 2 1 0 -1.B) 5 4 3 2 1 0 5 4 3 2 1 0.C) Error.D) 5 4 3 2 1 0 5 4 3 2 1 0 5 4 3 2 1 0.Answer: A

Predict the output of the following program.main(){int i=3;switch(i){default:printf("zero");case 1: printf("one");break;case 2:printf("two");break;case 3: printf("three");break;

Page 76: Total c Prog Bits(450)

}}

A) one.B) two.C) three .D) four.Answer: C

Which of the following is not a user-defined data type?struct book{Char name[10];Float price;Int pages;}

A) long int i=23.5B) enum day {Sun, Mon, Tue, Wed};C) union a

{112-C ProgrammingInt I;Char ch[ 2];} ;

D) none of these.Answer: B

Which of the following definition is correct?A) int length;B) char int;C) int long;D) float double;Answer: A

In the program given below, point out the error, if any, in the for loop.

#include<stdio.h>void main(){int i=1;for(;;){printf(�%d�,i++);if(i>10)break;}}

A) The condition in the for loop is a must.B) The two semicolons should be dropped.C) The for loop should be replaced by while loop.D) No error.Answer: D

Which of the following statements are correct about the program given below?

#include<stdio.h>void main(){int x=30, y=40;if(x==y)printf(�x is equal to y�);elseif(x>y)printf(�x is greater than y�);elseif(x<y)printf(�x is less than y�);

Page 77: Total c Prog Bits(450)

}A) Error: �Statement Missing�B) Error: �Expression syntax�C) Error: �Lvalue required�D) Error: �Rvalue required�Answer: A

Which of the following is not a logical operator?112-C Programming&.&&.||.!.

Answer: A