C Aptitude Questions 50

Embed Size (px)

Citation preview

  • 7/31/2019 C Aptitude Questions 50

    1/14

    C Aptitude Questions

    01) Which header file should you include if you are to develop a function that can accept

    variable number of arguments?

    a) Vararg.h b) stdlib.h

    c) stdio.h d) stdarg.h

    02) In a C program, constant is defined

    a) before main. b) after main.c) anywhere, but starting on a new line. d) none of the above.

    03) printf(%d.printf(tim*));

    a) result in a syntax error. b) outputs tim3.c) output garbage. d) prints tim and terminates abruptly.

    04) The rule for implict type conversion in C is

    a) int

  • 7/31/2019 C Aptitude Questions 50

    2/14

    08) In a C expression involving || operator, evaluation

    a) will be stopped if one of its components evaluates to false.b) will be stopped if one of its components evaluates to true.

    c) takes place from right to left.

    d) takes place from left to right.

    09) Which of the following statements is (are) correct ?

    a) enum variables can be assigned new values.

    b) enum variables can be compared.c) enumeration feature does not increase the power of C.

    d) all of the above.

    10) Which of the following comments regarding the reading of a string,using scanf (withoption) and gets is true ?

    a) Both can be used interchangeably.b) scanf is delimited by end of line, while gets is not

    c) scanf is delimited by blank , while gets is not.

    d) none of the above.

    11) Which of the following comments about the ++ operator is (are) correct?

    a) It is unary operator.b) The operand can come before or after the operator.c) It can not be applied to an expression.d) It associates from the right.e) all the above.

    12) When a variable of data type double is converted into float then

    a) rounding takes place.b) truncation takes place.c) the lower order bits are dropped.d) none of the above.

    13) Which of the following C statements is syntactically correct?

    a) for(); b) for(;);c) for(,); d) for(;;);

    14) Consider for loop in a C program.If the condition is missing

    Answers

  • 7/31/2019 C Aptitude Questions 50

    3/14

    a) it is assumed to be present and taken to be false.b) it is assumed to be present and taken to be true.c) it results in a syntax error.d) execution will be terminated.

    15) Which of the following statements about for loop are correct?

    a) index value is retained outside the loop.b) index value can be changed from within the loop.c) Goto can be used to jump,out of the loop.d) All of the above.

    16) Arrays can be initialized provided they are

    a) Automatic. b)External.c) Static. d)Both (2) and (3) above.

    17)| Arrays are passed as arguments to sa function by

    a) value. b) Reference.c) both (1) and (2) above. d) none of the above.

    18) It is necessary to declare the type of a function in the calling program if

    a) the function returns an integer.b) the function returns a non-integer value.c) the function is not defined in the same file.d) none of the above.

    19) The declaration void function 1(int)indicates the function 1 is a function which

    a) has no arguments.b) returns nothing.c) both(1) and (2) above.d) None of the above.

    20) Recursive functions are executed in a

    a) Last in first out order.b) First in first out order.c) Parallel fashion.d) all of the above.

    21) When a function is recursively called,all automatic variables

    a) are initialized during each execution.b) are retained from the last execution.

    Answers

  • 7/31/2019 C Aptitude Questions 50

    4/14

    c) are maintained in a stack.d) none of the above.

    22) A static variable

    a)

    cannot be initialized.b) is initialized once at the commencement of execution and cannot be changed at runtime.

    c) retains its value throughout the file of the program.d) is same as an automatic variable but is placed at the head of a program.

    23) An external variable

    a) is globally accessible by all functionsb) has a declaration extern associated with it when declared within a function.c) will be initialized to 0 if not initialized.d)

    all of the above.

    24) A switch statement is used to

    a) switch between functions in a program.b) switch from one variable to another variable.c) to choose from multiple possibilities which may arise due to different values of a

    single variable.

    d) to use switching variable.25) The statement #includeis written at the top of a program to indicate

    a) the beginning of the program.b) the program does heavy mathematical calculationsc) that certainly information about mathematical library functions are to be included at

    the beginning of the program.

    d) none of the above.26) What is the output of the following C program?

    main( )

    {

    extern int I;i=20;

    printf(%d,sizeof(i));

    }

    a) 2b) 4c) would vary from compiler to compiler.d) Error, i underdefined.

    Answers

  • 7/31/2019 C Aptitude Questions 50

    5/14

    27) What is the output of the following C program?

    main( ){

    extern int a;

    printf(\n%d,a);

    }int a=20;

    a) 0b) 20c) Error.d) Garbage value.

    28) What is the output of the following C program?

    main( ){extern int fun(float);

    int a;

    a=fun(3.14);printf(%d,a);

    }

    int fun(aa);

    float aa;{

    return ((int)aa);

    }

    a) 3.14b) 3.0c) 0d) Error.

    29) What is the output of the following C program?

    main( )

    {

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

    }

    a) Garbage values.b) 2 3 3

    Answers

  • 7/31/2019 C Aptitude Questions 50

    6/14

    c) 3 2 2d) 0 0 0

    30) What is the output of the following C program?

    main( )

    {Struct emp

    {

    char name[20];

    int age;flat sal;

    };struct emp e={Tiger};printf(\n%d%d%f,e.age,e.sal);

    a) Error.b) Garbage valuec) 00.0000000d) 10.000000

    31) In the following C program,find the error,if any?

    main( ){

    int i=1;

    for(; ;){

    printf(%d,i++);

    if(i>10)break;

    }

    }

    a) The condition is in the for loop is must.b) the two semicolons should be dropped.c) the for loop should be replaced by a while loop.d) No error.

    32) In the following C program,find out the error in the while loop,if any ?

    main( ){

    int i=1;

    Answers

  • 7/31/2019 C Aptitude Questions 50

    7/14

    While( )

    {printf(%d,i++);

    if(i>10)

    break;

    }

    }a) the condition in the while loop is a must.b) there should be atleast a semicolon in the while( ).c) the while loop should be replaced by for loop.d) No error.

    33) What is the output of the following C program?

    main( )

    {int i=2;printf(\n%d%d,++i,++i);

    }

    a) 3 4b) 4 3c) 4 4d) output may vary from compiler to compiler.

    34) What is the output of the following C program?

    main( )

    {

    int x=10,y=10,z=5,i;i=x

  • 7/31/2019 C Aptitude Questions 50

    8/14

    d) None of the above.36) In the following Ccode in which order the functions would be called?

    a= (f1(23,14)*12(12/4))+f3();

    a)

    f1,f2,f3b) f3,f2,f1c) The order may vary from compiler to compiler.d) None of the above.

    37) What is the output of the following C program?

    main( ){

    float a=0.7;if(a

  • 7/31/2019 C Aptitude Questions 50

    9/14

    printf(%f,sqrt(36.0));

    }

    a) 6.0b) 6c)

    6.000000d) Some absurd value.

    40) We want to round off x,a float, to an int value.What is the correct way to do so?

    a) y=(int)(x+0.5)b) y=int(x+0.5)c) y=(int) x+0.5;d) y=(int)((int)x+0.5).

    41) What error are you likely to get when you run the following program?

    main( )

    {

    struct emp{

    char name[20];

    float sal;

    }struct emp-e[10];

    int I;

    for(i=0;

  • 7/31/2019 C Aptitude Questions 50

    10/14

    pritnf(%d%d%d,sizeof(3.14f),sizeof(3.14),sizeof(3.14I));

    }

    a) 4 4 4b) 4 Garbage valuec)

    4 8 10d) Error

    44) If the binary equivalent of 5.375 in normalized form is 0100 0000 1010 1100 0000 0000

    0000,0000 what is the output of the following program ?

    main( )

    {

    float a=5.375;

    char *p;int I;

    p=(char *)&a;for(i=0;i

  • 7/31/2019 C Aptitude Questions 50

    11/14

    main();

    }

    a) Infinite number of times.b) 32767 times.c)

    65535 times.d) Till the stack doesn`t overflow.

    47) What is the output of the following C program?

    main( ){

    printf(5+Fascimile);

    }

    a) Errorb)

    Fascimilec) mile

    d) None of the above

    48) What is the output of the following C program?

    main( )

    {char str1[]=Hello

    char str2[]=Hello

    if(str1== str2)printf(\nEqual);

    else

    pirnt(\nUnequal);}

    a) Equalb) Unequalc) errord) None of the above.

    49) What is the output of the following C program?

    main( ){

    printf(%c,abcdefgh[4]);

    Answers

  • 7/31/2019 C Aptitude Questions 50

    12/14

    }

    a) Errorb) dc) ed)

    abcdefgh

    50) What is the output of the following C program?

    main( )

    {char str[7]=Strings;

    printf(%s,str);

    }

    a) Errorb)

    Stringsc) Cannot predict

    d) None of the above.

    Answers

  • 7/31/2019 C Aptitude Questions 50

    13/14

    ANSWERS

    1. d2. c3. b4. a5. d6. a7. d8. d9. d10. c11. 512. a13. d14. b15. 516. d17. b18. b19. b20. a21. a22. b23. d24. c25. c

    26. d27. b28. d29. d30. c31. d32. a33. d34. a35. c36. c37. a38. b39. d40. a41. b42. b43. c44. c45. c46. d47. c48. d49. c50. c

    Back

  • 7/31/2019 C Aptitude Questions 50

    14/14

    Back