Wednesday, October 8, 2008

C/ CPP Q & A

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?

1. printf("There's a "party" going on!\n");
2. printf("There's a \"party\" going on!\n");
3. printf("There's a "''party"'' going on!\n");
4. printf("There\'s a "party" going on!\n");
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?

1 printf("My salary was increased by 15%!\n");
2 printf("\"My salary was increased by 15%%!\"\n");
3 printf("\"My salary was increased by 15\%!\"\n");
4 printf("My salary was increased by 15'%'!\n");
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?

1. All I/O is buffered unless it is associated with interactive devices.
2. stdin and stdout are the only I/O buffered by default.
3. stderr and stdout are the only I/O buffered by default.
4. stdin is the only I/O buffered by default.
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?

1. #pragma
2. #options
3. #feature
4. #direct
5. #control

ANS : #pragma

5) Which header file defines system-dependent minimum and maximum values for integer types such as LONG_MAX?

1. ctype.h
2. sys.h
3 limits.h
4. int.h
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?

1. N_BITS_CHAR
2. CHAR
3 . CHAR_BIT
4. CHAR_BYTE
5. CH_BITS

ANS : CHAR_BIT

7) If there is NO header for a library, can its functions be used by a calling program?

1. Yes, the functions are discovered and resolved at run-time.
2. No, a header is needed to define what functions are available.
3. Yes, the calling program can use an extern function prototype of the function.
4. No, a header is needed for the program to execute properly.
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?

1. ++ptr;
2. ptr = ptr + sizeof(myArray);
3. ptr = ptr + sizeof(myStruct);
4. ptr = ptr + sizeof(ptr);
5. increment(ptr);

ANS : ++ptr;

9)What number is equivalent to 2.5e-2?

1. 0.025
2. 0.0025
3. 25
4. 250
5. 2500

ANS : 0.025

10) For which one of the following reasons do you use a volatile specifier?

1. To indicate to the compiler to optimize a variable that will be frequently changed
2. To identify a variable that may be modified by an external source
3. To specify that a variable be kept in a register because it will change frequently and registers are faster
4. To specify that a variable contain an automatic random number each time it is accessed
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.

Courtesy : Vishnu, Sr. T A, IBM, NY, USA

2 comments:

  1. good and informative questions
    continue ur good work

    ReplyDelete
  2. Good Work.
    Carry On ur work.
    Very useful and Informative.

    Swathy

    ReplyDelete