C Aptitude Questions And Answers – Volume II


1. What is the correct output of the following program?

        #include<stdio.h>
        void main()
        {
             enum a{yes,no,not_both};
             enum a ques1,ques2,ques3;
             ques1=no;
             ques2=yes;
             ques3=not_both;
             printf("%d %d %d",ques1,ques2,ques3);
        }

a) 2 1 3

b) 1 0 2

c) 1 2 3

d) 0 2 1

Answer

2. what will be the output of the following code?

        #include<stdio.h>
	void main()
	{
		struct student
		{
			char name[50];
			int total,mark1, mark2;
			float average;
		};

		struct student s={"Stan"};
		printf("%d %d %d %f",s.mark1,s.mark2,s.total,s.average);
	}

a) Error
b) Garbage value
c) 0 0 0 0.000000
d) Stan

Answer

3. Guess the output

        #include<stdio.h>
	void main()
	{
		int a=3;
		float b=3;
		clrscr();
		if(a==b)
			printf("same");
		else
			printf("different");
	}

a) same
b) different
c) Error
d) None of the above

Answer

4.  Which of the following output is correct?

        #include<stdio.h>
	void main()
	{
		char j=1;
                while(j<=255)
                {
                       printf("%d ",j);
                       j=j+1;
                }
        }

a) 1 2 3 …. 127
b) 1 2 3 ….. 255
c) 1 2 3 …. 127 -128 -127 … -2 -1 0 1 2 … 127 infinite times
d) 1 2 3 …. 255 -256 -255 …. -2 -1 0 1 2 …. 255 infinite times

Answer

5. What will be correct output of the program given below?

#include<stdio.h>
#define sqr(x) x*x
void main()
{
float a=10,b=30,c=2,d;
d=2*(a-b*c)/sqr(c);
printf("%f",d);
}
a) -100.000000
b) -25.000000
c) 0.000000
d) 25.000000

Answer

You may also like

3 Comments

  • Yuvan
    July 12, 2012 at 6:27 PM

    Nice Information. Thanks

  • Yuvan
    July 12, 2012 at 6:32 PM

    Nice Collections! Thanks.

    You can find some more great info here too

    http://infibee.com/general-aptitude/

  • jayadev
    January 20, 2013 at 8:35 PM

    It will be more helpfull if you specify the reason for the output.Like in the struct question if you remove the s={“Stan”} initialisation and leave just s as it is,it prints garbage values,not 0,0,0,0.000.Why???

LEAVE A COMMENT

Welcome To TechTwinklers!

Tech Twinklers is a Tech Blog run by Students with an aspiring enthusiasm in Technology and Gaming. This Blog will bring News about the Modern Technology, Educational Advances, Campus Interviews, etc. So make sure you subscribe to our blog because we don't want you to miss a thing that is posted here..

We're on Facebook!