Tokens and Control Structure in C++

  1. Which one of the following is an ANSI C keyword?
    • public
    • operator
    • export
    • volatile
  2. Which one of the following is not a C++ keyword?
    • constant
    • false
    • explicit
    • throw
  3. Which of the following statements is TRUE with regard to naming C++ identifiers?
    • A name can start with any letter or digit.
    • No special characters are permitted.
    • Uppercase and lowercase letters are distinct.
    • A name cannot have more than 32 characters
  4. Which of the following is a valid C++ identifier?
    • Total value
    • 2 x
    • _string1
    • template
  5. Which of the following is not a valid literal constant in C++?
    • “ANSI C++”
    • 0X5
    • 12, 345
    • 9.234L
  6. Which of the following is a user-defined data type in C++?
    • array
    • enumeration
    • void
    • function
  7. Which of the following is not a built-in data type in C++?
    • structure
    • void
    • char
    • long double
  8. Which of the following program segments is valid in C++?
    • a) void *p1; char *p2; p2 = p1;
    • b) void *p1; int *p2; *p2 = *p1;
    • C) void *p1; char *p2; p2 =(char*)p1;
    • d) enum colour {red, blue}; colour background; background = 1;
  9. Assuming that we are working an a 16-bit word machine, which of the following takes a size of 8 bytes
    • signed long int
    • long int
    • long double
    • double
  10. Which of the following declaration statements is illegal?
    • const int m = 10;
    • const int count;
    • const m = 100;
    • int const *p = &x;
  11. Which of the following statements is FALSE?
    • All variables must be declared before they are used
    • All variables must be given a type when they are declared
    • A variable can be declared anywhere in the scope
    • A variable must be initialized at the time of its declaration
  12. Identify the error, if any, in the statement: long sum = m1 + m2;
    • Declaration cannot contain any expression
    • Initialization at the time of declaration is not valid.
    • Type specification is incomplete.
    • No error
  13. Which of the following statements is invalid?
    • int p = new int ;
    • int *p = new int ;
    • int *p = new int [10] ;
    • int *p = new int [m] [10] ;
  14. For using the manipulator setw(), we must include the header file:
    • <iostream>
    • <cstdio>
    • <iomanip>
    • <cstdlib>
  15. The following statements implement type cast operation. Which one of them is illegal?
    • x = y/(float)m;
    • x = y/float(m);
    • x = float(y)/(float)m;
    • x = y/float m;
  16. The statement a=(b=10) – 5; is an example of
    • Chained assignment
    • Embedded assignment
    • Compound assignment
    • None of the above
  17. Which one of the following expressions is an example of bitwise expression?
    • x>=y
    • x==10 && y<5
    • x << 10
    • x + = 10
  18. Which of the following operators in C++ can be overloaded?
    • Conditional operator (?:)
    • Scope resolution operator (::)
    • Member access operator (.*)
    • Relational Operator (<=)
  19. In which of the following groups all the operators are in the same level of precedence?
    • <<, < =, = =, << =
    • new, sizeaf, typeid, !
    • new, delete, ->, ::
    • %, *, ->*, /=
  20. Which of the following loop structures is known as an exit-controlled loop?
    • do… while loop
    • while loop
    • for loop
    • None of the above

Answers:

  1. volatile
  2. constant
  3. No special characters are permitted.
  4. _string1
  5. 12, 345
  6. enumeration
  7. structure
  8. void *p1; char *p2; p2 =(char*)p1;
  9. double
  10. const int count;
  11. A variable must be initialized at the time of its declaration
  12. Type specification is incomplete.
  13. int p = new int ;
  14. <iomanip>
  15. x = y/float m;
  16. Embedded assignment
  17. x << 10
  18. Scope resolution operator (::)
  19. <<, < =, = =, << =
  20. do… while loop

Related posts