NEW
Font size
WorksheetsC/C++ programming basics
Total questions: 50
Worksheet time: 36mins
The statements in the body of a while loop may never be executed while the statements in the body of a do-while loop will be executed
at least once
at least twice
never
as many times as the user wishes
What will be the output of the following code?
int i=1;
for ( ; ; )
cout << ++i;
1 2 3 4 5. . . (infinite)
2 3 4 5 6. . . . (infinite)
error
can't say
If you want a user to enter exactly 20 values, which loop would be the best to use?
while
switch
do-while
for
How many times will the above loop display "Hello world!"?
19
20
21
an infinite number of times
What is the output of the above program?
0 1 2 3 4
0 1 2 3
0 1 2 4
0 1 2
Loops in C Language are implemented using?
While Block
For Block
Do While Block
All the above
If block always need to be associated with a else block?
True
False
Choose a right C Statement.
Loops or Repetition block executes a group of statements repeatedly
Loop is usually executed as long as a condition is met
Loops usually take advantage of Loop Counter
All the above
The conditional operator are also known as
Relational operator
Binary operator
Ternary operator
Chary operator
If you have to make decision based on multiple choices, which of the following is best suited?
if
if-else
if-else-if
All the above
Can we use string inside switch statement?
Yes
No
In situations where we need to execute body of the loop before testing the condition, we should use __________.
for
while
do while
nested for loop
What is the output of the above program?
0 1 2 3 4
0 1 2 3
0 1 2
0 1
Choose a correct C Statement.
a++ is (a=a+1) POST INCREMENT Operator
a-- is (a=a-1) POST DECREMENT Opeartor
--a is (a=a-1) PRE DECREMENT Opeator
++a is (a=a+1) PRE INCREMENT Operator
All the above.
What is the way to suddenly come out of or Quit any Loop in C Language.?
continue; statement
leave; statement
break; statement
quit; statement
What will be the output of the following program?
a) 0 1 2 3 4
b) 5
c) Error
d) No output
How many arrows should come out of a decision symbol in a flowchart?
0
1
2
3
What does selection mean?
Selection is following instructions in order.
Selection is to repeat something over and over again
Selection is when you have a choice of options
Selection is choosing the best option
int x;
int y;
int z;
x=3;
y=4;
z = ++x * y++;
cout<<z;
12
16
20
0
Which of the following comments about the ++ operator are correct?
1) It is a unary operator
2) The operand can come before or after the operator
3)It associates from the right
1 and 3
1 and 2
2 and 3
1,2,3
Which of the following is not a Bitwise operator?
&
|
<<
&&
16>>2
4
8
32
64
What is the output of the following code:
#include<stdio.h>
void main()
{
int a=10,b=-5;
printf("%d",a&&b);
}
1
0
Error
10
-5
What will be the output of the following program?
a) 10 11 12 13 ...
b) 10
c) No output
d) Infinite loop
What is the output of the following code snippet:
int a=12;
a?printf("GEC"):printf("IT");
GEC
IT
GECIT
Error
What will be the output of the following program?
a) 0 1 2 3 4
b) Infinite loop
c) 0 0 0 0 0
d) No output
Which of the following is a valid way to declare a variable in C?
int 1a;
int a1;
float a-b;
char a@;
What will be the output of the following code:
int x = 5; printf("%d", x++);
5
Error
6
None
Which of the following statements is true about the 'break' statement?
It can only be used in loops.
Both a and b
It can be used to exit a function.
It can be used to exit a switch statement.
Which of the following is true about the 'continue' statement?
It terminates the program.
It can only be used in switch statements.
It skips the current iteration of a loop.
It can be used in any block of code.
What is the output of the following code snippet: for(int i=0; i<5; i++) { printf("%d ", i); }?
0 1 2 3 4 5
No output
0 1 2 3 4
1 2 3 4 5
Which of the following statements about nested loops is correct?
They are not allowed in C programming.
They can only be used with for loops.
They can improve performance in all cases.
They allow a loop to be executed within another loop.
What is the output of C Program.?
int main() {
int a[3] = {10,12,14};
a[1]=20;
int i=0;
while(i<3)
{ printf("%d ", a[i]);
i++; }
}
20 12 14
10 20 14
10 12 20
Error
What is the output of C program.?
int main() {
int a[3] = {10,12,14};
int i=0;
while(i<3)
{ printf("%d ", i[a]);
i++; }
}
14 12 10
10 10 10
10 12 14
None
8.Which of the following correctly accesses the seventh element stored in arr, an array with 100 elements?
arr[6]
arr[7]
arr{6}
arr{7}
What is the minimum and maximum Indexes of this below array.?
int main()
{
int ary[9];
return 0;
}
-1, 8
0, 8
1,9
None of the above
Which of the following gives the memory address of the first element in array foo, an array with 100 elements?
foo[0];
foo;
&foo;
foo[1];
Choose a correct array statement.
An array size can not changed once it is created.
Array element value can be changed any number of times
To access Nth element of an array students, use students[n-1] as the starting index is 0.
All the above
Explain the concept of pointer arithmetic with an example in C++.
Pointer arithmetic involves multiplying a pointer by an integer value to access elements of an array.
Pointer arithmetic in C++ is used to perform mathematical operations on the memory address of a pointer.
In C++, pointer arithmetic can only be performed on pointers to primitive data types.
Pointer arithmetic in C++ involves adding or subtracting an integer value to/from a pointer to access elements of an array. For example, if 'ptr' is a pointer to an integer, then 'ptr + 1' will point to the next integer in memory.
What happens when you subtract one pointer from another in C++?
It gives the sum of the two pointers
It gives the number of elements between the two pointers, divided by the size of the type to which the pointers point.
It gives the difference of the two pointers
It gives the product of the two pointers
The __________, also known as the address operator, returns the memory address of a variable.
asterisk (* )
ampersand ( & )
percent sign ( % )
exclamation point ( ! )
What does the following statement do?
double *num2;
Declares a double variable named num2
Declares and initializes a pointer variable named num2
Initializes a pointer variable named num2
Declares a pointer variable named num2
Assuming ptr is a pointer variable, what will the following statement output?
cout << *ptr;
the value stored in the variable whose address is contained in ptr
the string "*ptr"
the address of the variable whose address is stored in ptr
the address of the variable stored in ptr
A pointer variable is designed to store
any legal C++ value
only floating-point values
an integer
a memory address
How do you assign the address of variable score to pointer pScore in C++?
pScore = *score;
pScore = &score;
pScore = score;
pScore = score&;
What does the expression *pScore = newScore; do?
It reassigns pScore to point to newScore.
It changes the value of pScore to the address of newScore.
It changes the value of the object that pScore points to, to the value of newScore.
It creates a new pointer called newScore.
How are the elements of an array stored in memory?
In a non-contiguous block of memory
In a contiguous block of memory
In a random order in memory
In separate memory locations for each element
What do the following declaration signify? char *arr[10];
arr is a array of 10 character pointers.
arr is a array of function pointer
. arr is a array of characters
. arr is a pointer to array of characters
What is the output of the following program int main()
{
int a = 20;
//a memory location = 1234
printf("%d %d %d %d", a, &a, *(&a));
return 0; }
20 20 20
20 1234 1234
20 1234 20
1234 20 1234
"&" is called as ___________ in pointer concept.
Conditional Operator
Address Operator
Logical Operator
None of these
