Sunday, October 5, 2008

C/CPP Questions and Answers

Some Q n A ( Bold letters are the right answers)


Each pass through a loop is called a/an

[a] enumeration

[b] iteration

[c] culmination

[d] pass through

Which looping process checks the test condition at the end of the loop?

[a] for

[b] while

[c] do-while

[d] no looping process checks the test condition at the end

A continue statement causes execution to skip to

[a] the return 0; statement

[b] the first statement after the loop

[c] the statement following the continue statement

[d] the next iteration of the loop

In a group of nested loops, which loop is executed the most number of times?

[a] the outermost loop

[b] the innermost loop

[c] all loops are executed the same number of times

[d] cannot be determined without knowing the size of the loops

The statement i++; is equivalent to

[a] i = i + i;

[b] i = i + 1;

[c] i = i - 1;

[d] i --;

Which looping process is best used when the number of iterations is known?

[a] for

[b] while

[c] do-while

[d] all looping processes require that the iterations be known

What's wrong? for (int k = 2, k <=12, k++)

[a] the increment should always be ++k

[b] the variable must always be the letter i when using a for loop

[c] there should be a semicolon at the end of the statement

[d] the commas should be semicolons

What's wrong? while( (i <> 24))

[a] the logical operator && cannot be used in a test condition

[b] the while loop is an exit-condition loop

[c] the test condition is always false

[d] the test condition is always true

If there is more than one statement in the block of a for loop, which of the following must be placed at the beginning and the ending of the loop block?

[a] parentheses ( )

[b] braces { }

[c] brackets [ ]

[d] arrows < >

What's wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);

[a] the question mark should be an equal sign

[b] the first semicolon should be a colon

[c] there are too many variables in the statement

[d] the conditional operator is only used with apstrings


Which of the following does not have class scope?

A. public accesss specifiers
B private access specifiers
C protected access specifiers
D All have class scope



Courtesy : Reshma Vijayan, S7 LBSITW, TVM


1 comment:

  1. Most of the question looks simple and straight forward. Please go through these questions and select good ones and format it with html tags.

    1)
    There's a "party" going on!
    Question Which one of the following statements produces the line of text above?

    Choice 1
    printf("There's a "party" going on!\n");
    Choice 2
    printf("There's a \"party\" going on!\n");
    Choice 3
    printf("There's a "''party"'' going on!\n");
    Choice 4
    printf("There\'s a "party" going on!\n");
    Choice 5
    printf("There''s a "party" going on!\n");

    ANS
    printf("There's a \"party\" going on!\n");

    2)
    "My salary was increased by 15%!"
    Question Which one of the following statements exactly reproduces the line of text above?
    Choice 1
    printf("My salary was increased by 15%!\n");
    Choice 2
    printf("\"My salary was increased by 15%%!\"\n");
    Choice 3
    printf("\"My salary was increased by 15\%!\"\n");
    Choice 4
    printf("My salary was increased by 15'%'!\n");
    Choice 5
    printf("\"My salary was increased by 15'%'!\"\n");

    ANS
    printf("\"My salary was increased by 15%%!\"\n");

    3)
    According to the ANSI standard, what types of I/O are buffered by default?
    Choice 1
    All I/O is buffered unless it is associated with interactive devices.
    Choice 2
    stdin and stdout are the only I/O buffered by default.
    Choice 3
    stderr and stdout are the only I/O buffered by default.
    Choice 4
    stdin is the only I/O buffered by default.
    Choice 5
    Input I/Os are the only I/O buffered by default.

    ANS
    All I/O is buffered unless it is associated with interactive devices.

    4) What directive instructs the compiler to turn certain compiler-defined features on or off?
    Choice 1
    #pragma
    Choice 2
    #options
    Choice 3
    #feature
    Choice 4
    #direct
    Choice 5
    #control

    ANS
    #pragma

    5)
    Which header file defines system-dependent minimum and maximum values for integer types such as LONG_MAX?
    Choice 1
    ctype.h
    Choice 2
    sys.h
    Choice 3
    limits.h
    Choice 4
    int.h
    Choice 5
    stddef.h

    ANS
    limits.h

    6)
    The size of a char can vary between one implementation of C and another.
    Referring to the statement above, which compiler-defined constant holds the number of bits in a char?
    Choice 1
    N_BITS_CHAR
    Choice 2
    CHAR
    Choice 3
    CHAR_BIT
    Choice 4
    CHAR_BYTE
    Choice 5
    CH_BITS

    ANS
    CHAR_BIT

    7)
    If there is NO header for a library, can its functions be used by a calling program?
    Choice 1
    Yes, the functions are discovered and resolved at run-time.
    Choice 2
    No, a header is needed to define what functions are available.
    Choice 3
    Yes, the calling program can use an extern function prototype of the function.
    Choice 4
    No, a header is needed for the program to execute properly.
    Choice 5
    No, a header is required for the program to link.

    ANS
    Yes, the calling program can use an extern function prototype of the function.

    8)
    myStruct *ptr;
    myStruct myArray[10];
    ptr=myArray;

    Referring to the sample code above, which one of the following is the correct way to increment the variable "ptr" to point to the second element of myArray?
    Choice 1
    ++ptr;
    Choice 2
    ptr = ptr + sizeof(myArray);
    Choice 3
    ptr = ptr + sizeof(myStruct);
    Choice 4
    ptr = ptr + sizeof(ptr);
    Choice 5
    increment(ptr);

    ANS
    ++ptr;

    9)What number is equivalent to 2.5e-2?
    Choice 1
    0.025
    Choice 2
    0.0025
    Choice 3
    25
    Choice 4
    250
    Choice 5
    2500

    ANS
    0.025

    10)
    For which one of the following reasons do you use a volatile specifier?
    Choice 1
    To indicate to the compiler to optimize a variable that will be frequently changed
    Choice 2
    To identify a variable that may be modified by an external source
    Choice 3
    To specify that a variable be kept in a register because it will change frequently and registers are faster
    Choice 4
    To specify that a variable contain an automatic random number each time it is accessed
    Choice 5
    To specify that a variable be kept in temporary space that is released when it goes out of scope

    ANS
    To identify a variable that may be modified by an external source

    will update more questions on free time.

    Vishnu IBM NY

    ReplyDelete