In: Computer Science
QUESTION 1
The statement char ch = ‘A’ would store in ch
A. |
The character A |
|
B. |
ASCII value of A |
|
C. |
A along with the single inverted commas |
|
D. |
Both (a) and (b) |
2 points
QUESTION 2
Which of the following scanf() statement will you use to accept following variables?
float gravity_a;
double gravity_b;
A. |
scanf("%f %lf", &gravity_a, &gravity_b); |
|
B. |
scanf("%LF %f ", gravity_a, gravity_b); |
|
C. |
scanf("%LF %LF ", &gravity_a, &gravity_b); |
|
D. |
scanf("%f %LF ", gravity_a, gravity_b); |
2 points (Extra Credit)
QUESTION 3
What will be the output of the following program?
#include<stdio.h>
int main()
{
float a=6.15528;
printf("%2.1f\n", a);
return 0; }
A. |
6.00 |
|
B. |
6.15 |
|
C. |
6.2 |
|
D. |
6 |
2 points (Extra Credit)
QUESTION 4
What will be the output of the following statements?
const int count = 10;
count++; printf("%d", count);
A. |
10 |
|
B. |
11 |
|
C. |
Run-time Error |
|
D. |
Compile-time Error |
3 points
QUESTION 5
What will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 5, b = 2;
printf("%d ", a+++b);
printf("%d %d", a, b);
return 0;
}
A. |
Results in Syntax Error |
|
B. |
Prints 7 6 2 |
|
C. |
Prints 8 6 2 |
|
D. |
None of the above |
QUESTION 1
The statement char ch = ‘A’ would store in ch
A. |
The character A |
The option A suits well, Char data type will store the character value in it, So ch will hold the Character A.
QUESTION 2
Which of the following scanf() statement will you use to accept following variables?
float gravity_a;
double gravity_b;
A. |
scanf("%f %lf", &gravity_a, &gravity_b); |
The option A suits well,
As the format for scanf to get the value of float is %f and the format for scanf to get the value double is %lf. so the correct format to get the input is A option.
QUESTION 3
What will be the output of the following program?
#include<stdio.h>
int main()
{
float a=6.15528;
printf("%2.1f\n", a);
return 0; }
C. |
6.2 |
The option C suits well
The formatting of %2.1f will represent 2 digits before decimal point and one digit after decimal point in float data type.
Thus the option is C.
QUESTION 4
What will be the output of the following statements?
const int count = 10;
count++; printf("%d", count);
D. | Compile-time Error |
The option D will be suitable.
count is declare as const - constant variable
As we can increment a constant variable, incrementing count will lead to compile time error of incrementing a read-only variable.
QUESTION 5
What will be the output of the following program?
#include<stdio.h>
int main()
{
int a = 5, b = 2;
printf("%d ", a+++b);
printf("%d %d", a, b);
return 0;
}
B. | Prints 7 6 2 |
The option B suits well,
As per the increment operator precedence a+++b will be executed as (a++) + (b) thus a will be incremented to 6.