Elementary level C and C++
This quiz has 20 questions on ' Elementary level C and C++'. (Whew..!) Enter the alphabet for your answer for each question and press 'Done' button. Your answers alongwith the correct answers will be displayed.

The number of bytes of storage occupied by short, int and long are
A. 2, 2 and 4 B. 2, 4 and 4 C. 4, 4 and 4 D. Machine dependent
Your answer : Correct answer :

When do you not use the keyword 'return' when defining a function?
A. Always B. Never C. When the function returns void D. For function main()
Your answer : Correct answer :

int i[2], j; int *pi;
i[0] = 1; i[1] = 5; pi = i;
j = *pi + 1 + *(pi + 1)
Value of j after execution of the above statements will be
A. 7 B. 6 C. 4 D. 3
Your answer : Correct answer :

A function can make the value of a variable available to another by
A. declaring the variable as global variable B. Passing the variable as a parameter to the second function C. Either of the two methods in (A) and (B) D. Neither (A) nor (B)
Your answer : Correct answer :

Evaluate the following expression as C++ would do :
8 * 9 + 2 * 5
A. 82 B. 79 C. 370 D. 440
Your answer : Correct answer :

Given below are three different ways to print the character for ASCII code 88. Which is the correct way?
1) char c = 88; cout << c << "\n";
2) cout.put(88);
3) cout << char(88) << "\n";
A. 1 B. 2 C. 3 D. All the three are ok.
Your answer : Correct answer :

if (i = 0)
printf ("True");
else
printf("False");
Under what conditions will the above print out the string "True"?
A. Never B. Always C. When the value of i is 0 D. When the value of i is not 0
Your answer : Correct answer :

i = 25;
switch (i) {
case 25: printf("The value is 25\n");
case 30: printf("The value is 30\n");
When the above statements are executed the output will be :
A. The value is 25 B. The value is 30
C.
The value is 25
The value is 30 D. None of the above
Your answer : Correct answer :

count = 0;
for (i=1; i <= 10; i++);
count = count + i;
Value of count after execution of the above statements will be
A. 0 B. 11 C. 55 D. 100
Your answer : Correct answer :

struct screen_pos
{ int row, col } ;
move_right(cursor)
struct screen_pos *cursor;
{ cursor.col++; } /* This statement has a syntax error */
What is the correct statement?
A. cursor.col = cursor.col + 1; B. col.cursor++; C. *cursor.col++; D. cursor->col++;
Your answer : Correct answer :

What will be the output for the following piece of code?
cout << (int *) "Home - Mohan Iyer";
A. Nothing B. Home - Mohan Iyer C. Some garbage D. Address of the string "Home - Mohan Iyer"
Your answer : Correct answer :

Study the following C program :
call_me (myvar)
int myvar;
{ myvar +- 5; }
main()
{
int myvar;
myvar = 3;
call_me(myvar);
printf("%d\n",myvar);
What will be printed?
A. 3 B. 5 C. 8 D. 0
Your answer : Correct answer :

This is a variation of the call_me function in the previous question:
call_me (myvar)
int *myvar;
{ *myvar += 5; }
The correct way to call this function from main() will be
A. call_me(myvar) B. call_me(*myvar) C. call_me(&myvar) D. call_me()
Your answer : Correct answer :

typedef enum { html, java, javascript, perl, cgi } lang;
The above statement defines a :
A. Union B. User defined type C. Enumerated variable D. Structure
Your answer : Correct answer :

What would the following code segment print?
int k = 8;
do
cout << "k = " << k << "\n";
while k++ < 5;
A. 13 B. 5 C. 8 D. Infinite loop
Your answer : Correct answer :

Which operators cannot be overloaded?
A. Sizeof B. .* C. :: D. All the three
Your answer : Correct answer :

What does a derived class inherit from a base class?
A. Only the Public members of the base class B. Only the Protected members of the base class C. Both the Public and the Protected members of the base class D. None
Your answer : Correct answer :

If one class contains another class as a member, in what order are the two class constructors called?
A. Constructor for the member class is called first B. Constructor for the member class is called second C. Only one of the constructors is called D. Compiler error
Your answer : Correct answer :

cin.ignore(80, _\n_);
This statement
A. ignores all input B. ignores the first 80 characters in the input C. ignores all input till end-of-line D. ignores all input after 80 characters
Your answer : Correct answer :

main()
{
char *str;
scanf("%s",str);
printf("%s",str); }
The error in the above program is :
A. Variable 'str' is not initialised B. Format control for a string is not %s C. Parameter to scanf is passed by value. It should be an address D. Incorrect syntax
Your answer : Correct answer :

While you are here, may I request you to sign my Guestbook please?       Public         Private

Visit this week's quiz page
Return to my homepage