Last Updated on April 23, 2022 by Admin 3
Basic data types, operations, and flow control (decision-making statements) M2 Test
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(viod) { int i, j, k; i = 2; j = -2; if(i) i++; if(j) j++; k = i * j; printf("%d",k); return 0; }
-1
-2
1
2
-
What is the value of the
x
variable at the end of the following snippet?float x; x = 1. / 2 * 3; /***
1.5
1
2
- 0
-
What is the decimal value of the following integer literal?
0x8
8
100
10
- the literal is invalid
-
What is the value of the
c
variable at the following snippet?char c; c = '\';
- the assignment is invalid and causes a compilation error
\
'
\0
-
Which line of code must you insert in order for the program to program to produce the expected output?
Expected output:
1
Code:
#include <stdio.h> int main() { var = 1; printf("%d \n", var); return 0; }
int var;
placed above
var = 1;
int var;
placed below
var = 1;
int var;
placed below
printf("%d \n", var);
- No change are required – the program will compile and produce the expceted output
-
What is the value of the
var
variable at the end of the following snippet?int var; var = 2; var = var * var; var = var + var; /* var = var / var; var = var % var; */
8
1
0
16
-
What is the value of the
k
variable at the end of the following snippet?int i, j, k; i = 3; j = -3; k = (i >= i) + (j <= j) + (i == j) + (i > j);
3
2
1
0
-
What is the value of the
k
variable at the end of the following snippet?int i, j, k; i = 3; j = -3; k = i * j; k += j; k /= i;
-4
-8
4
- 8
-
What is the value of the
k
variable at the end of the following snippet?int i, j, k; i = 4; j = -5; k = --i * j++;
15
12
16
18
-
Which of the following identifiers is a vaild variable name?
Monte_Carlo
Monte-Carlo
Monte Carlo
Monte@Carlo
-
What is the value of the
var
variable at the end of the following snippet?int var; var = 2; var = var * var; var = var + var; var = var / var; var = var % var;
0
1
8
16
-
What is the value of the
x
variable at the end of the following snippet?int x; x = 1 / 2;
0
1
2
0.5
-
What is the value of the following floating-point literal?
8765E-2
87.65
8.765
876.5
0.8765
-
What is the value of the
x
variable at the end of the following snippet?int x; x = 1 / 2 * 3; /* */
0
1
2
1.5
-
Which of the following identifiers is an invalid variable name?
0_
_0_
_0
___
-
What is the decimal value of the following integer literal?
08
the literal is invalid
8
1000
10
-
What is the value of the
k
variable at the end of the following snippet?int i, j, k; i = 4; j = 5; k = 1-- * ++j;
24
20
21
18
-
What is the value of the
c
variable at the end of the following snippet?char c; c = 'a'; c -= ' ';
A
a
\0
- the assignment is invalid and causes a compilation error
-
Is the following declaration valid?
int var, var;
No
- Yes
-
Which of the following is a proper integer number (in the”C” language sense)?
123456
123,456
123.456
123_456