C Aptitude Questions and Answers


1. Guess the output

main()

{

float a=8.4;

double b=8.4;

if (a==b)

pritnf (“Both are same”);

else

printf (“They are different”);

}

2. Which of the following statements should be used to  obtain the reminder after dividing 56.4/6.3?

a.  rem = 56.4%6.3;

b. rem = fmod(56.4,6.3);

c. rem = modf(56.4,6.3);

d.  Remainder cannot be obtained for floating point division

3. How will you round off the value 7.66 to 8.0 ?

a. roundto(7.66);

b. ceil(7.66);

c. floor(7.66);

d. roundup(7.66);

4. What will be the output of the following program?

void main()

{

int a=3;

switch(a)

{

case 1:

printf (” Hello “);

break;

case 2:

printf (” Hai “);

break;

case 3:

continue;

case 4:

printf (“Hi”);

break;

}

}

a. HiHelloHai

b. Hi

c. Hello

d. error

5. In which header file NULL macro is defined?

a. stdio.h

b. stddef.h

c. stdlib.h

d. both ‘a’ and ‘b’

6. A pointer is a

a. A variable that stores address of other variable

b. A variable that stores address of an instruction

c. A keyword used to create variables

d. All the above

7. What will be the output of the following code?

void main()

{

static int i=i++, j=j++;

printf (“i= %d\t j= %d”,i,j);

}
8.  What does fp points to in the below program?
main()

{

FILE *fp;

fp= fopen(“sample”,”r”);

return 0;

}

a. The first character of the file

b. The last character in the file

c. A structure which contains a char pointer which points to the last character of the file

d. A structure which contains a char pointer which points to the first character of the file

9. What will be the output of the code?

#define square(a) a*a

main()

{

int i;

i= 4/square(2);

printf(“%d”, i);

}

10.  Which of the following function sets first n characters of a string to a given character?

a. strinit()

b. strset()

c. strnset()

d. strcset()

 

 

ANSWERS

1.  They are different

2. (b) rem = fmod( 56.4,6.3)

3. (b) ceil(7.66);

4.  (d) error

5.  (d) both ‘a’ and ‘b’

6.  (a) A variable that stores the address of another variable

7. i=1                    j=1

8. ( d) A structure which contains a char pointer which points to the first character of the file

9.  4

10. (c) strnset()

You may also like

2 Comments

  • panneer selvam
    June 30, 2011 at 4:32 AM

    in question no. 9 , how square(2) must give 4 right , but how the values of i returning 1 ??

    • Kirthika
      June 30, 2011 at 7:56 AM

      First it’ll define the value for square(2) as 2*2
      so, we’ll get 4/2*2
      since there is no bracket, we have to follow BODMAS, the precedence is from left to right.
      Now 1st it’ll evaluate 4/2=2, then 2*2=4.

      So the Answer is 4!!

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!