C Programs (GATE)

Practice questions for predicting C program outputs - GATE exam preparation

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

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
Question 2 Multiple Choice (Single Answer)

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
Question 3 Multiple Choice (Single Answer)

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
Question 4 Multiple Choice (Single Answer)

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
Question 5 Multiple Choice (Single Answer)

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
Question 6 Multiple Choice (Single Answer)

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
Question 7 Multiple Choice (Single Answer)

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
Question 8 Multiple Choice (Single Answer)

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
Question 9 Multiple Choice (Single Answer)

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
Question 10 Multiple Choice (Single 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
Question 11 Multiple Choice (Single Answer)

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
Question 12 Multiple Choice (Single Answer)

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
Question 13 Multiple Choice (Single Answer)

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
Question 14 Multiple Choice (Single Answer)

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
Question 15 Multiple Choice (Single Answer)

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