C Programming

Comprehensive C programming quiz covering control structures, functions, file I/O, structures, type casting, and logical operators. Suitable for GATE, MCA, and Information Technology exam preparation.

11 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What will be the output of the following program if 'n' key is pressed after execution of program?
#include<stdio.h>
#include<process.h>
void main()
{char ch;
printf("enter Y/y to continue");
scanf("%c",&ch);
if(ch=='y' || ch=='Y')
printf("Yes");
else
exit(1);
}

Consider the letters written like A, B, C, V are the keys prssed by user. User can press any key, we have considered following keys has been prssed.

  1. Yes
  2. Exit from program
  3. Error: exit function should have prototype
  4. No
  5. None of these
Question 2 Multiple Choice (Single Answer)

Which of the following functions have exactly same working?
(a) putch()
(b) putchar()
(c) puts()
(d) fputs()
(e) fputchar()

  1. b and c
  2. a, b and e
  3. d and e
  4. a, b, d and e
  5. all of these
Question 3 Multiple Choice (Single Answer)

Which of the following describes the function of strcmpi()?

  1. Compares two strings regardless of case
  2. Compares the portion of one string with portion of another string
  3. Compares the portion of one string with portion of another string regardless of case
  4. All of the above
  5. None of the above
Question 4 Multiple Choice (Single Answer)

Which of the following is not true about while and do while loop?
(a) while loop is entry control and do-while is exit control.
(b) do-while must be executed atleast once and while loop may execute once or not.
(c) ‘;’ is given after while in both while and do-while loop.
(d) Condition is given in while statement in both while and do-while loop.

  1. b and d
  2. a, b and d
  3. only c
  4. all of these
  5. none of these
Question 5 Multiple Choice (Single Answer)

Which of the following case constants in switch-case is/are not allowed?
(a) case ‘S’: and case ‘s’:
(b) case a + b: and case a + 3:
(c) case i <= 20:
(d) case 7 - 3:
(e) case 3.14:

  1. only b
  2. b,c and e
  3. a and d
  4. all a,b,c,d and e
  5. none of the above
Question 6 Multiple Choice (Single Answer)

What will be the output of following program code?
#include<stdio.h>
<stdio.h><stdio.h>main()
</stdio.h><stdio.h>{
int k; float j;</stdio.h><stdio.h>
j=9.0/2; k=9/2.0;
</stdio.h><stdio.h>printf(%dt%ft,k,j);</stdio.h><stdio.h>
j=9/2; k=9/2;</stdio.h><stdio.h>
printf(%dt%ft,k,j);
</stdio.h><stdio.h>k=9.0/2.0;</stdio.h><stdio.h> j=2/9.0;
</stdio.h><stdio.h>printf(%dt%ft,k,j);
}</stdio.h></stdio.h>

  1. 4.000000 4.500000 4.000000 4 0.222222 4
  2. 4 4.500000 4 4.000000 0.222222 4
  3. 4 4.500000 4 4.000000 4 0.222222
  4. 4 4 4 4 4 0.000000
  5. None of these
Question 7 Multiple Choice (Single Answer)

What does the following program code do?
#include<stdio.h><stdio.h><stdio.h>
void </stdio.h><stdio.h>main()</stdio.h><stdio.h>
{FILE *f;char ch;</stdio.h><stdio.h>
int noi=0;
</stdio.h><stdio.h>f=open(“d.txt”,”r”);
</stdio.h><stdio.h>while(1)
</stdio.h><stdio.h>{ ch=fgetc(f);
</stdio.h><stdio.h>if(f==EOF)</stdio.h><stdio.h>
break;</stdio.h><stdio.h>
if(ch==’ ‘)</stdio.h><stdio.h>
noi++’;}
</stdio.h><stdio.h>fclose(f);</stdio.h><stdio.h>
printf(“No. of …….=%d”,noi);}</stdio.h></stdio.h>

  1. Counts total number of character in file d.txt
  2. Counts number of blanks in file d.txt
  3. Counts number of tabs in file d.txt
  4. Counts number of lines in file d.txt
  5. Counts total number of characters in file ‘C’ source file
Question 8 Multiple Choice (Single Answer)

Which of the following is not true about loops in ‘C’?

  1. Working of while and do-while loop is same.
  2. while(1) is infinite loop and exit() can be written to come outside the loop.
  3. for(;;) implements an infinite loop.
  4. A break statement takes the execution control out of the loop.
  5. A continue statement skips the execution of the statements after the control to the beginning of the loop.
Question 9 Multiple Choice (Single Answer)

Which of the following structure declarations and structure variable's syntax is correct?

  1. struct test
    { int k; char ch; };
    struct test t1,t2;
  2. struct test
    { int k; char ch; }t1,t2;
  3. struct
    { int k; char ch; }t1,t2;
  4. struct test
    { int k; char ch; };
    test t1,t2;
  5. struct test
    { int k; char ch; };
    struct test t[4];
Question 10 Multiple Choice (Single Answer)

Which is the correct format for type casting in C? (Consider the following program code.)
include<stdio.h><stdio.h><stdio.h>
main()
</stdio.h><stdio.h>{int x=100,y=7;
</stdio.h><stdio.h>float z;z=……..;
</stdio.h><stdio.h>prinf(“z=%f”,z);}</stdio.h></stdio.h>

  1. float(x/y)
  2. (float)x/y
  3. (float)(x/y)
  4. x/y
  5. none of these
Question 11 Multiple Choice (Single Answer)

What will be the output of following program code?
#include<stdio.h><stdio.h><stdio.h>
main()
</stdio.h><stdio.h>{int a=10,b=12,c=0;
</stdio.h><stdio.h>if(!(a>5&&c))
</stdio.h><stdio.h>{ printf(%d,a!=6&&b>5);
</stdio.h><stdio.h> printf(%d,a==10||b<15&&c<1); }
</stdio.h><stdio.h>else</stdio.h><stdio.h>
printf(If expression is wrong);}</stdio.h></stdio.h>

  1. 11
  2. 10
  3. 01
  4. 00
  5. 'If' expression is wrong.