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

CPP Q Bank My Answers

Cpp q Bank My Answers uni

Uploaded by

mariammosayed5
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)
47 views

CPP Q Bank My Answers

Cpp q Bank My Answers uni

Uploaded by

mariammosayed5
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/ 8

Faculty of Computers and Course: Programming Fundamentals

Information Code : CS141


Assiut University Prof. Dr. Khaled F. Hussain
2019/2020 - Spring 2020
Assiut
University

Question Bank

Choose the correct answer for the following questions:

1. Out of the following, find those identifiers, which cannot be used for naming
Variable, Constants or Functions in a C++ program:
a) Column31
b) _Amount
c) NeW
d) Total*Tax

2. Find the correct identifiers out of the following, which can be used for naming
Variable, Constants or Functions in a C++ program:
a) switch
b) 1stName
c) name1
d) Add+Subtract

3. Which C++ header file is essentially required to be included to run/execute the


following C++ code:

void main(){
char *word1="Hello";
cout<<word1;
}

a) ctype
b) iostream
c) math
d) iomanip

4. Observe the following C++ code and write the name(s) of the header file(s),
which will be essentially required to run it in a C++ compiler:

void main( ){
int Number;
Number=-5;
Number =abs(Number);}

a) ctype
b) iostream
c) math
d) iomanip

5. Write the names of the header file to which the setw belong:
a) ctype
b) iostream
c) math
d) iomanip

6. Write the names of the header file to which the isupper( ) belong:
a) ctype
b) iostream
c) math
d) iomanip

7. Observe the following C++ code very carefully and select the line number that has
syntactical error. Note: Assume all required header files are already being
included in the program.
[1] #define SIZE = 100
[2] void main( ){
[3] int x1=6;
[4] if(x1=7) x1=3;}

a) 1
b) 2
c) 3
d) 4

8. Observe the following C++ code very carefully and select the line number that has
syntactical error. Note: Assume all required header files are already being
included in the program.
[1] int main( ){
[2] Double x1=6;
[3] if(7<x1<=2)
[4] x1+=3;}

a) 1
b) 2
c) 3
d) 4

9. …………..variables are those variables which are not declared within any
function or scope. So, these variables can be accessed by any function of the
program.
a) Global
b) Local
c) New
d) General

10. …………..method, the called function creates a new set of variables and copies
the values of arguments into them. The function does not have access to the
original variables (actual parameters) and can only work on the copies of values it
created.
a) Call by reference
b) Call by value
c) Call by pointer
d) Call by vector

11. Which of the following correctly declares an array?


a) int array{10};
b) array[10];
c) int array[10];
d) Float array[10];

12. What is the index number of the last element of an array with 100 elements?
a) 100
b) 99
c) 0
d) Programmer-defined

13. Which of the following accesses the 344th element stored in array?
a) array[343];
b) array[344];
c) array(343);
d) Array(344);

14. Write the output of the following C++ program code. Note: Assume all required
header files are already being included in the program.

int main)({
int const p = 10;
cout << ++p;
return 0;
}

a) 10
b) 11
c) Error
d) None of the mentioned

15. The difference between a and ‘a’ is


a) The first one refers to a variable whose identifier is a and the second one refers
to the character constant a
b) The first one is a character constant a and second one is the string literal a.
c) Both are the same
d) None of the mentioned

16. The escape sequence '\n' means


a) Newline
b) Tab
c) Backspace
d) Backslash

17. Which operator is having the highest precedence?


a) increment (postfix) ++
b) increment (pretfix) ++
c) multiplication *
d) assignement =

18. What is this operator called ?: ?


a) Relational
b) Casting operator
c) Conditional
d) None of the mentioned

19. What is the output of the program below?

#include <iostream.h>
main()
{
int n = 4;
cout << n++ <<” “<<++n;
}

a) 4 6
b) 4 5
c) 5 6
d) 6 6

20. What is the output of the program below?

#include <iostream.h>
main() {
int n = 3;
if (n > 3);
{
cout << n * n << “ “;
--n;}
cout << n;
}
a) 3
b) 2
c) 9 2
d) 4 1

21. The Conditional operator can be replaced by which operator?


a) Bitwise operator
b) if..else statement
c) Multiplicative operator
d) none of the mentioned

22. Which looping process is best used when the number of iterations is known?
a) for
b) while
c) do-while
d) all looping processes require that the iterations be known

23. Where does the execution of the program starts?


a) user-defined function
b) main function
c) void function
d) none of the mentioned

24. What is the scope of the variable declared in the user defined function?
a) whole program
b) only inside the {} block
c) both a and b
d) none of the mentioned

25. How many minimum number of functions is need to be presented in c++?


a) 0
b) 1
c) 2
d) 3

26. What will you use if you are not intended to get a return value from a function?
a) static
b) const
c) volatile
d) void
27. When will we use the function overloading?
a) different function name but same number of arguments
b) same function name and same number of arguments
c) different function name and different number of arguments
d) same function name but different number of arguments

28. What will happen while using pass by reference


a) The values of those variables are passed to the function so that it can
manipulate them
b) The location of variable in memory is passed to the function so that it can use
the same memory area for its processing
c) The function declaration should contain @ in its type declaration
d) All of the mentioned

29. What can be used to input a string with blankspace?


a) inline
b) getline
c) putline
d) None of the mentioned

30. What is meant by ofstream in c++?


a) Writes to a file
b) Reads from a file
c) Both a & b
d) None of the mentioned

31. Identify the correct statement


a) Namespace is used to group class, objects and functions.
b) Namespace is used to mark the beginning of the program.
c) Namespace is used to separate the class, objects.
d) None of the above

32. Which of the following functions will correctly return true if its argument is an
odd integer?
a) bool IsOdd (int x) { return (x / 2 == 1); }
b) bool IsOdd (int x) { if (x % 2 == 0) return true; else return false; }
c) bool IsOdd (int x) { return (x % 2 == 1); }
d) bool IsOdd (int x) { return (x % 2 == 0); }

33. Which of the following functions will correctly swap the contents of the two
integers i and j?
a) void swap (int a, int b) { int temp; temp = a; a = b; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
b) void swap (int &a, int &b) { int temp; temp = a; a = b; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
c) void swap (int a, int b) { int temp; temp = a; b = a; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }
d) void swap (int &a, int &b) { int temp; temp = a; b = a; b = temp; }
int main () { int i = 0, j = 1; swap (i, j); }

34. Consider this piece of code:


void mysterious(int i, int &k) { i = 1; k = 2; }
int main () { int x = 0; mysterious (x, x); cout << x << endl; return 0; }
What is the value of x that gets printed by the main?
a) 0
b) 1
c) 2
d) None of these

35. Compilation is the step in the software development cycle where this type of
errors is detected.
a) logic errors
b) semantics errors
c) specification errors
d) syntax errors

36. All of these are C++ keywords except:


a) else
b) switch
c) using
d) constant

37. What is the value stored in the integer variable intVar? int intVar = 24.2 / 2;
a) 12
b) 12.1
c) 13
d) None of the above

38. What is wrong with the following code fragment?


int main() {
int x=4,y=3; // line 1
const int i = 10; // line2
x = x + i; // line 3
i = y*2; // line 4
}
a) Variables are not declared before use
b) There cannot be 3 variables in such a simple program
c) There is an error in line 3
d) There is an error in line 4
39. For the following code fragment, how many times does sum get incremented? In
other words how many times is line X executed in the following program?

for(int i=0;i<3;i++)
for (int j=0;j<3;j++)
sum++;
a) 2
b) 3
c) 4
d) 9

40. How many times is the body of the loop executed?


int i=1; while(true) {
cout << i;
if(i==5) break;
i++;
}
a) 0 times
b) 4 times
c) 5 times
d) Forever

You might also like