Cs-111 Introduction To Programming: Terminal Exam 8 July 2021
Cs-111 Introduction To Programming: Terminal Exam 8 July 2021
Terminal Exam
A. Comment on a local and global variable. What is the precedence when there are a Global
variable and local variable in the program with the same name?
B. Suppose that you have the declaration int *numPtr;. What is the difference between the
expressions *numPtr and &numPtr?
C. Explain the difference between formal and actual parameters during the call by reference and
call by value with the help of an example.
D. Consider the following statements to identify valid or invalid statements along with a reason.
i.
char string15[16];
if(string15 >= "Nice day")
cout << string15;
ii.
int myList[5] = {0, 4, 8, 12, 16};
int yourList[5];
yourList = myList;
B. Write a C++ function, power(), that takes as parameters two integers x and y such that x is
nonzero and returns 𝑥 𝑦 . You can use the following definition to calculate 𝑥 𝑦 . If y ≤ 0:
𝑝𝑜𝑤𝑒𝑟(𝑥, 𝑦) = 1 𝑖𝑓 𝑦 = 0,
𝑥 𝑖𝑓 𝑦 = 1,
𝑥 𝑥 𝑝𝑜𝑤𝑒𝑟( 𝑥, 𝑦 − 1) 𝑖𝑓 y > 1
mark the following statements as “Yes” if they output QAU. Otherwise, mark the statement as
“No” and explain why it does not output QAU.
A. cout << name;
B. cout<<name[];
C. for (int j = 0; j < 6; j++)
cout << name[j];
D. int j = 0;
while (name[j] != '\0')
cout << name[j++];
E. int j = 0;
while (j < 8)
cout << name[j++];
int N = 2,137;
main (){
int a, b, c, d:
a := 3;
b = 5;
c = c + d;
N = a + n;
for (i = 3; i <= N; i++){
cout << setw(5) << i;
i = i + 1; }
return 0; }
GOOD LUCK