Exam overview
Reread my other post CS204, and keep on prayin.
Also read the DISCLAIMER!
Ze Exam
Section 1 MCQs
This section was Multiple Choice Questions.???
is a choice that I forgot :')
Which of the following is NOT a logical operator?
&
&&
||
!
Show Answer
&
Which of the following transfers control to the calling function?
switch
return
goto
???
Show Answer
return
Which is best suidted to get strings that contain spaces from the users.
scanf
printf
puts
gets
Show Answer
gets
Performs operation then checks condition
for
do-while
while
???
Show Answer
do-while
How many times does the following code repeat?
for (i=1; i <=10; i=i-1)
Forever
Never
1
-
Show Answer
Forever
What is the order of operations in the following code?
z = x + y * z / 1 % 3 -2
*%/-+=
*/%+-=
=+*/%-
-%/*+=
Show Answer
The second one
strcmp
returns what when the string are equal?
1
0
-1
first string
Show Answer
0
Which of the following isn’t an arithmatic operation?
!=
/=
+=
%=
Show Answer
!=
Which of the following is NOT a correct use of pointers?
int arr[i];
int arr[] = {1, 2 3}
int * char;
int char
Show Answer
int char
What would you use add two string?
strcon
strcmp
strcat
stradd
Show Answer
strcat
Which of the following is the correct way to declare constants?
#define a = b
const char a 'b'
const char a = 'b'
const char
Show Answer
const char a = 'b'
How do you declare a function
return-type func-name (argument type);
return-type func-name (argument type){}
return-type (argument type) func-name;
???
Show Answer
I am not sure if it is the one with
;
or{}
. Either first or second
How NOT to declare a 2D array?
int a[3][] = {{1, 2, 3}, {5, 5, 6}, {6, 7, 8}}
int a[][3] = {{1, 2, 3}, {5, 5, 6}, {6, 7, 8}}
int a[1][3]
Show Answer
the first answer
What is the output of the following?
char str1[50];
char str1[] = "Hello World";
printf("%s\n", strcpy(str1 ,str2)):
Hello
Hello World
- Nothing
- Error
Show Answer
Not sure, I think ‘Hello World’
How do you declare a zero Array?
int a[5] = {};
int a[5];
int a = 0, b = 0, c = 0;
int array[5] = {a, b, c}
- All of the Above
Show Answer
All of the Above
Section 2: Output of the program
Program 1:
What is the output of the following code?
#include <stdio.h>
int add(int a, int b);
int main(){
int a = 10, b = 20, c;
c = add(a, b);
printf("c = %d\n", ++c);
}
int add(int a, int b){
return (a + (++b);
}
Show Answer
c = 32
Program 2
What is the output of the following code?
#include <stdio.h>
int main(){
int a[5] = {1, 10, 5, 13, 40};
int i, j, k, m;
i = ++a[1];
j = a[1]++;
k = j++;
m = a[k++];
printf("%d %d %d %d", i, j, k, m);
}
Show Answer
11, 12, 12, 192929 (any number)
Section 3: Correct The Errors
Program 1
#include <stdin.h>
int main(){
int n,i;
scanf("%f", &n);
for(i=0; i < 10 + n, i++)
printf("%d", n);
return 0;
}
in the Show Error 1
stdin
should be stdio
Show Error 2
scanf
should use %d
instead of %f
Show Error 3
for
loop ,
should be ;
Program 2
Correct the program so that it prints “This number is odd” and “This number is even” for odd and even numbers, respectively.
#include <stdio.h>
int main(){
int value;
printf("Please input the number");
scanf("%d", &value);
switch (value/2){
case 0: printf("This number is odd");
case 1: printf("This number is even");
}
return 0;
}
should use missing break after case 0 Switch case 0 and 1.Show Error 1
%
instead of /
Show Error 2
Show Error 3
Section 3: Code
Code for a triangle program
Code a program to validate a triangle, a valid triangle has all of its
angles = 180
.
Example output:
Please input 3 angles: 90 45 45
This triangle is valid
Please input 3 angles: 90 90 90
This triangle is invalid
Show Answer
Code it yourself.
Code to find the sum of an array
Use pointers to find the sum of the following array by using a
function named sum
that does the sum.
int a[5] = {1, 2, 3, 4, 8};