Test Series - cpp

Test Number 14/102

Q: Choose the correct option.

    extern int i;
    int i;
A. both 1 and 2 declare i
B. 1 declares the variable i and 2 defines i
C. 1 declares and defines i, 2 declares i
D. 1 declares i,2 declares and defines i
Solution: The keyword extern is not a definition and is not allocated storage until it is initialized.
Q: Pick the right option.

Statement 1: A definition is also a declaration.
Statement 2: An identifier can be declared just once.
A. Statement 1 is true, Statement 2 is false
B. Statement 2 is true, Statement 1 is false
C. Both are false
D. Both are true
Solution: An identifier can be declared many times must be defined just once.
Q: Which of the given statements are false?

i. extern int func;
ii. extern int func2(int,int);
iii. int func2(int,int);
iv. extern class foo;
A. iii and iv only
B. ii and iii only
C. only iv
D. ii, iii and iv
Solution: No extern are allowed for class declarations.
Q: Pick the right option.

Statement 1: Global values are not initialized by the stream.
Statement 2: Local values are implicitly initialised to 0.
A. Statement 1 is true, Statement 2 is false
B. Statement 2 is true, Statement 1 is false
C. Both are false
D. Both are true
Solution: Global values are implicitly initialised to 0, but local values have to be initialised by the system.
Q: Can two functions declare variables(non static) with the same name?
A. No
B. Yes
C. Yes, but not a very efficient way to write programs
D. No, it gives a runtime error
Solution: We can declare variables with the same name in two functions because their scope lies within the function.
Q: Identify the type of variables.

    typedef char* CHAR;
    CHAR p,q;
A. char*
B. char
C. CHAR
D. unknown
Solution: The statement makes CHAR a synonym for char*.
Q: What does the following statement mean?

int (*fp)(char*)
A. pointer to a pointer
B. pointer to an array of chars
C. pointer to function taking a char* argument and returns an int
D. function taking a char* argument and returning a pointer to int
Solution: The (*fn) represents a pointer to a function and char* as arguments and returning int from the function. So according to that, the above syntax represents a pointer to a function taking a char* as an argument and returning int.
Q: The operator used for dereferencing or indirection is ____
A. *
B. &
C. ->
D. –>>
Solution: * is used as dereferencing operator, used to read value stored at the pointed address.
Q: Choose the right option.

string* x, y;
A. x is a pointer to a string, y is a string
B. y is a pointer to a string, x is a string
C. both x and y are pointers to string types
D. y is a pointer to a string
Solution: * is to be grouped with the variables, not the data types.
Q: Which one of the following is not a possible state for a pointer.
A. hold the address of the specific object
B. point one past the end of an object
C. zero
D. point to a type
Solution: A pointer can be in only 3 states a, b and c.

You Have Score    /10