CNIT 105 MIDTERM QUESTIONS & ANSWERS
What is the extension of the source file of a 'C' program? - Answers -.c
Which of the following is the standard way to scan a float variable x? float x;
scanf("%f", x);
scanf("%.2f", &x);
scanf("%f", &x);
scanf("%d", &x); - Answers -scanf("%f", &x);
Which of the following is the standard way to print a character variable c: char c = 'C';
printf("%d", c);
printf("%c", c);
printf("%c", &c);
printf("%s", c); - Answers -printf("%c", c);
In a C program, the execution begins with which functions? - Answers -main() function
When you don't want the function to return anything, which of the following return types
will you use? - Answers -void()
Which of the following options is a prototype of the given function?int divide(int a, int b){
return a / b;
}
int divide(a, b);
int divide(int, int);
void divide(int a, int b);
int divide(); - Answers -Int divide(int, int);
Identify the problem in the following code
float compute(int a, int b){
float answer; answer = a / b;
} - Answers -Function doesn't return anything
How many times will the loop in the following code run
int main(){
int n = 1;
int sum = 0;
while(n <= 10){
sum = sum + n;
}
printf("Sum of numbers from 1 to 10 is: %d", sum);} - Answers -The loop will run
infinitely many times
, What is the scope of a variable? - Answers -It is the segment of the code where the
variable can be used
What will be the output of the following code
int n; for (n = 1; n <= 10; n++)
{
printf ("%d ", n);
} - Answers -1 2 3 4 5 6 7 8 9 10
What is the scope of the variables a and b in the given function:
float multiply(int a, int b)
{
return a * b;
} - Answers -Only function compute
What is the return type of the following function prototype:
int myFunction(char c, float f, double d); - Answers -Int
What will be the output of the following code segment:
int num = 1;
while (num <= 5)
{
printf("%d, ", (num*num));
num++;
} - Answers -1,4,9,16,25
Which of the following is a valid invocation for the function myFunction():
void myFunction(){ printf("CNIT105 is awesome");}
myFunction();
myFunction;
myFunction("CNIT105 is awesome");
None of the above - Answers -myFunction();
What is the output of the following code segment:
int n = 100;
do {
printf ("%d \n", n);
n = n + 5;
} while (n <= 10); - Answers -100
What will be the output of the following code segment:
int counter = 1;
while (counter <= 99)
{counter++;}
printf("%d", counter) - Answers -100
What is the extension of the source file of a 'C' program? - Answers -.c
Which of the following is the standard way to scan a float variable x? float x;
scanf("%f", x);
scanf("%.2f", &x);
scanf("%f", &x);
scanf("%d", &x); - Answers -scanf("%f", &x);
Which of the following is the standard way to print a character variable c: char c = 'C';
printf("%d", c);
printf("%c", c);
printf("%c", &c);
printf("%s", c); - Answers -printf("%c", c);
In a C program, the execution begins with which functions? - Answers -main() function
When you don't want the function to return anything, which of the following return types
will you use? - Answers -void()
Which of the following options is a prototype of the given function?int divide(int a, int b){
return a / b;
}
int divide(a, b);
int divide(int, int);
void divide(int a, int b);
int divide(); - Answers -Int divide(int, int);
Identify the problem in the following code
float compute(int a, int b){
float answer; answer = a / b;
} - Answers -Function doesn't return anything
How many times will the loop in the following code run
int main(){
int n = 1;
int sum = 0;
while(n <= 10){
sum = sum + n;
}
printf("Sum of numbers from 1 to 10 is: %d", sum);} - Answers -The loop will run
infinitely many times
, What is the scope of a variable? - Answers -It is the segment of the code where the
variable can be used
What will be the output of the following code
int n; for (n = 1; n <= 10; n++)
{
printf ("%d ", n);
} - Answers -1 2 3 4 5 6 7 8 9 10
What is the scope of the variables a and b in the given function:
float multiply(int a, int b)
{
return a * b;
} - Answers -Only function compute
What is the return type of the following function prototype:
int myFunction(char c, float f, double d); - Answers -Int
What will be the output of the following code segment:
int num = 1;
while (num <= 5)
{
printf("%d, ", (num*num));
num++;
} - Answers -1,4,9,16,25
Which of the following is a valid invocation for the function myFunction():
void myFunction(){ printf("CNIT105 is awesome");}
myFunction();
myFunction;
myFunction("CNIT105 is awesome");
None of the above - Answers -myFunction();
What is the output of the following code segment:
int n = 100;
do {
printf ("%d \n", n);
n = n + 5;
} while (n <= 10); - Answers -100
What will be the output of the following code segment:
int counter = 1;
while (counter <= 99)
{counter++;}
printf("%d", counter) - Answers -100