0

C Programs (GATE)

Description: C Programs (GATE)
Number of Questions: 15
Created by:
Tags:
Attempted 0/15 Correct 0 Score 0

Find the output of the following C program:

main(){int i=0;while(++i<=10) printf(%d, i);}

  1. 1 to 10

  2. 0 to 9

  3. 1 to 9

  4. 0 to 10

  5. None of these


Correct Option: A
Explanation:

First incrementation of i takes place, then comparison of value of i with 10 is performed, then the program prints values from 1 to 10.

Find the output of the following C program:

main(){int i=0;while(i++<10)printf(%d,i);}

  1. 0 to 9

  2. 1 to 10

  3. Syntax error

  4. Infinite loop

  5. None of these


Correct Option: A
Explanation:

while(i++<10) first compares value of i with 10, then increments i, and then prints the values of i from 0 to 9.

Find the output of the following C program:

main(){extern int i;i=20;printf(%d,sizeof(i));}

  1. 2

  2. 4

  3. Would vary from compiler to compiler

  4. Error

  5. None of these


Correct Option: D
Explanation:

There will be linker error also.

Find the output of the following C program:

Main(){int i;For(i=1;i <=10;i ++){Printf(%d ”,i);i=i+1;}}

  1. 1 to 10

  2. 1 to 9

  3. 0 to 9

  4. Syntax error

  5. None of these


Correct Option: A
Explanation:

This program prints 1 to 10 because the for loop prints values from 1 to 10.

Find the output of the following C program:

Main(){int i;For(;i <=10;i ++){printf(%d ”,i);}}

  1. 1 to 10

  2. 0 to 9

  3. 1 to 9

  4. Infinite loop

  5. None of these


Correct Option: A
Explanation:

Initialisation is done before for loop and all conditions in the for loop are satisfied, and the program prints values from 1 to 10.

Find the output of the following C program:

main(){printf(%c, abcdefgh[4]);}

  1. Error

  2. d

  3. e

  4. abcdefgh

  5. None of these


Correct Option: C
Explanation:

It returns the value of 4th position.

Find the output of the following C program:

main(){extern int a;printf(%d, a);}int a =20;

  1. 0

  2. 20

  3. Error

  4. Garbage value

  5. None of these


Correct Option: A
Explanation:

Extern int a automatically initialises to 0; so the correct answer is 0.

Find the output of the following C program:

main(){int x=10,y=10,z=5,i;i=x}

  1. 1

  2. 0

  3. Error

  4. 5

  5. None of these


Correct Option: A
Explanation:

10<10 returns 0, <5 returns 1.

Find the output of the following C program:

main(){char str[7]=Strings;printf(%s,str);}

  1. Infinite loop

  2. Strings

  3. Cannot be predicted

  4. Error

  5. None of these


Correct Option: B
Explanation:

It displays 'Strings' as the answer.

Find the output of the following C program:

main(){printf(5+Fascimile);}

  1. Error

  2. Fascimile

  3. Mile

  4. Fasci

  5. None of these


Correct Option: C
Explanation:

Value of 5th position is mile.

Find the output of the following C program:

Main(){int i;For(i=1;i <=10;i ++);{Printf(%d ”,i);i=i+1;}}

  1. Infinite loop

  2. Syntax error

  3. 1 to 10

  4. 1 to 9

  5. None of these


Correct Option: A
Explanation:

Semicolon for loop generates infinite loop.

Find the output of the following C program:

main(){char ch='A';printf(%d%d,sizeof(ch),sizeof(A));}

  1. 1 1

  2. 1 2

  3. 2 2

  4. 2 1

  5. Error


Correct Option: B
Explanation:

sizeof(ch) = 1 and sizeof('A') = 2

Find the output of the following C program:

main(){int i=2;printf(%d %d,++i,++i);}

  1. 3 4

  2. 4 3

  3. 4 4

  4. Output may vary from compiler to compiler

  5. None of these


Correct Option: A
Explanation:

Value of i = 2, ++i = 3 and ++i = 4.

Find the output of the following C program:

main(){printf(hello);main();}

  1. Infinite loop

  2. 32767 times

  3. 65535 times

  4. Error

  5. Till the stack doesn't overflow


Correct Option: E
Explanation:

Stack keeps on executing until it overflows.

Find the output of the following C program:

main(){int a[5]={2,3};printf(%d%d%d,a[2],a[3],a[4]);}

  1. Garbage value

  2. 2 3 3

  3. 3 2 2

  4. 0 0 0

  5. None of these


Correct Option: D
Explanation:

a[5] = {2, 3, 0, 0, 0}; so the value of a[2] = 0, a[3] = 0 and a[4] = 0.

- Hide questions