0% found this document useful (0 votes)
58 views

C++ Questions

Uploaded by

Eliyas Etana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

C++ Questions

Uploaded by

Eliyas Etana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

C+++ Questions

1. Which looping process is best used when the number of iterations is known?
a. While loop
b. For loop
c. Do while loop
d. all looping processes require that the iterations be known
2. Where does the execution of the program starts?
a. User-defined function
b. Main function
c. Void function
d. None of the above
3. Variable names must begin with ___
a. #
b. $
c. Number
d. Letter
4. What is the output of this program?
Note:Includes all required header files
using namespace std;
void fun(int p, int q)
{
p = 20;
q = 10;
}
int main()
{
int p = 10;
fun(p, p);
cout << p;
return 0;
}
a. 10
b. 20
c. compile time error
d. none of the mentioned
5. Which is true for b, if b is defined as "int *b[10];"?
a. The definition only allocates 10 pointers and does not initialize them
b. Initialization must be done explicitly
c. The definition only allocates 10 pointers and does not initialize them & Initialization
must be done explicitly
d. Error
6. In following statement which statement are correct?
a. char *X3=”ABC”;
b. char X1[]=”ABC”;
c. char X2[5]=”ABC”;
d. None of these
7. Which of the following gives the memory address of the first element in array?
a. array[0];
b. array[1];
c. array[2];
d. array[3];
8. Which of the following is not a comment in C++?*
a. // This is a comment
b. /* This is a multi-line comment */
c. # This is a comment
d. None of the above
9. Which of the following is a correct identifier in C++?
a. 7var_name
b. 7VARNAME
c. VAR_1234
d. $var_name
10. What will happen in the following C++ code snippet?
int a =100, b =200;
int *p = &a, *q = &b ;
p=q
a. b is assigned to a
b. p now points to b
c. a is assigned to b
d. q now points to a
11. 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
12. In which direction does the assignment operation will take place?
a. left to right
b. right to left
c. top to bottom
d. bottom to top
13. Which of the following is a properly defined structure?
a. struct {int a;}
b. struct a_struct {int a;}
c. struct a_struct int a;
d. struct a_struct {int a;};
14. 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
15. The continue statement inside a loop causes the control to go to —————
a. Beginning of the loop
b. B. Skipping statements inside a loop for the current iteration
c. C. Both a and b
d. None of the above
16. Which of the following is a standard input stream in C++?
a. cin
b. cout
c. cerr
d. All of the above
17. One of the following statement has the same meaning as int *ptr;
a. int* ptr;
b. int ptr;
c. *int ptr;
d. int ptr*;
18. What is the effect of writing a break statement inside a loop?
a. It cancels remaining iterations.
b. It skips a particular iteration.
c. The program terminates immediately.
d. Loop counter is reset.
19. ________ is used to initialize a pointer.
a. the address of an existing object
b. the value of an integer variable
c. the value of a floating-point variable
d. all of these
20. If we want a function to work on the original argument in the calling function, we must
pass the argument as by ————
a. Parameter
b. Call by value
c. Call by reference
d. None of the above
21. Choose a correct C++ do while syntax.
a. dowhile(condition){ // statements };
b. do while(condition){ // statements };
c. do{ // statements }while(condition)
d. do{ // statements }while(condition);
22. Which of the following is a valid identifier in C++?
a. my_variable
b. 123abc
c. this_is_a_long_identifier
d. #include
23. The operator used for dereferencing or indirection is ____
a. *
b. &
c. ->
d. –>>
24. What is the output of this program?
using namespace std;
void copy (int& a, int& b, int& c)
{
a *= 2; b *= 2; c *= 2;
}
int main ()
{
int x = 2, y = 5, z = 7;
copy (x, y, z);
cout << "x =" << x << ", y =" << y << ", z =" << z;
return 0;
}
a. x =3, y =7, z =10
b. x =3, y =6, z =5
c. x =4, y =10, z =14
d. None of the above
25. Which of the following are invalid statements?
a. float num1 = &ptr2;
b. int ptr = &num1;
c. int ptr = int *num1;
d. All of these are invalid
26. 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
27. The ————– operator can be used only with two integer operands.
a. Modulus operator or %
b. Increment operator
c. Decrement operator
d. None of the above
28. 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. none of the above
29. Typical bit width of char is?
a. 0 byte
b. 1byte
c. 2byte
d. 3byte
30. The value 132.54 can be represented using which data type?
a. Double
b. Void
c. Int
d. bool
31. 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
32. 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
33. 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
34. The destination statement for the go to label is identified by what label?
a. $
b. @
c. *
d. :
35. 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
36. What will be the output of this program?
Note:Includes all required header files
using namespace std;
int main() {
int find[] = {1, 2, 3, 4};
int *p = (find + 1);
cout << *p;
return 0; }
a. 1
b. 2
c. 3
d. 4
37. Which of the following is a function in C++?*
a. int main() { }
b. void my_function() { }
c. int add(int x, int y) { return x + y; }
d. All of the above
38. ___________are used to change the order of precedence in the evaluation of expressions.
a. Parenthesis
b. Curly brackets
c. Box bracketed
d. All of the above
39. Which of the following correctly declares an array in C++?
a. array{10};
b. B. array array[10];
c. C. int array;
d. int array[10];
40. What is the name of this | operator?
a. Size of
b. Or
c. And
d. modulus
41. Integer values are stored in ___ bit format in binary form.
a. 8
b. 16
c. 32
d. 64
42. The lowest address of array is?
a. 0
b. 1
c. 2
d. 3
43. Which of the following is a statement in C++?*
a. int x = 10;
b. while (x > 0) { x--; }
c. if (x == 10) { cout << "x is equal to 10"; }
d. All of the above
44. What will happen in this code?
int a = 100, b = 200;
int *p = &a, *q = &b
p = q;
a. b is assigned to a
b. p now points to b
c. a is assigned to b
d. q now points to a
45. Which of the following function declaration is/are incorrect?
a. int Sum(int a, int b = 2, int c = 3);
b. int Sum(int a = 5, int b);
c. int Sum(int a = 0, int b, int c = 3);
d. Both B and C are incorrect.
46. In flowchart rectangle symbol indicates:
a. Input/Output
b. Connector
c. Process
d. Decision
47. Choose a correct C++ for loop syntax.
a. for(initalization; condition; inc/dec){ // statements };
b. for(declaration; condition; incrementoperation){ // statements };
c. for(declaration; incrementoperation; condition){ // statements };
d. for(initalization; condition; incrementoperation){ // statements };
48. What is the output of this program?
#include <iostream>
using namespace std;
int main()
{
int x = 1, y = 3, z = 5;
int *lfc[ ] = {&x, &y, &z};
cout << lfc[1];
return 0;
}
a. 1
b. 3
c. 5
d. it will return some random number

You might also like