C Essentials – Part 1: SUMMARY TEST
-
What happens if you try to compile and run program?
#include <stdio.h> int main(void) { int i, t[4]; t[3] = 0; for(i = 1; i >= 0; i--) t[i] = t[3] * i; printf("%d", t[1]); return 0; }
- the program outputs
0
- the program outputs
1
- the program outputs
2
- the program outputs
3
- the program outputs
-
What happens if you try to compile and run program?
#include <stdio.h> int main(void) { int* a, b; b = 1; a = &b; b = 2; printf("%d\n", b); printf("%d", *a); return 0; }
- 2
2
- 1
2
- 1
1
- 2
1
- 2
-
What happens if you try to compile and run program?
#include <stdio.h> int main(void) { int i, j; i = 1; j = 1; while(i > 16) { i += 4; j++; } printf("%d", j); return 0; }
- the program outputs
1
- the program outputs
5
- the program outputs
0
- the program outputs
4
- the program outputs
-
What is the value of the following integer literal?
013
11
13
19
- the literal is invalid
-
What happens if you try to compile and run program?
#include <stdio.h> int fun(){ int a; return ++a; } int main() { printf("%d", fun()); return 0; }
- the program outputs
1
- the program outputs
0
- the program outputs
a
- the program causes an error
- the program outputs
-
What is the value of the
var
variable at the end of the following snippet?int var; var = 3; var = var * var; /* var = var + var; */ /* var = var / var; var = var % var; */ var = var - 1;
- 8
- 9
- 7
- -1
-
What is the value of the
var
variable after the execution of the following snippet of code:int var; var = -1; var = var + 1; var = var + var;
- the program outputs
0
- the program outputs
-1
- the program outputs
1
- the program outputs
2
- the program outputs
-
What happens if you try to compile and run program?
#include <stdio.h> int main() { int arr[5] = {1, 2, 3, 4, 5}; arr[1] = 0; arr[3] = 0; for(int i = 0; i < 5; ++i) { printf(%d ", arr[i]) } return 0; return 0; }
- 1 0 3 0 5
0 2 0 4 5
0 0 0 4 5
1
-
What happens if you try to compile and run program?
#include <stdio.h> int main(void) { int i, j, k; i = 1; j = 3; if(j) j--; else i++; if return 0; }
- the program outputs
2
- the program outputs
1
- the program outputs
0
- the program outputs
-1
- the program outputs
-
What happens if you try to compile and run program?
#include <stdio.h> int main(void) { int i = 1, j = -1; for(;;){ i *= 2; j++; if(i >= 16) break; } print("%d", j); return 0; }
- the program outputs
3
- the program outputs
2
- the program outputs
1
- the program outputs
0
- the program outputs
-
Which of the following examples are legal ways of initializing the
arr
array?Select two answers.
int arr[3] = {1, 2, 3};
int arr[] = {1, 2, 3};
- int arr{3} = {1, 2, 3};
- int arr{3} = [1, 2, 3];
-
What is the value of the following integer literal?
0x22
34
- 22
- 18
- the literal is invalid
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = -1, j = 3; for(j > 0; j; j--) i *= 2; printf("%d", i + j); return 0; }
- the program outputs
-8
- the program outputs
-4
- the program outputs
0
- the program enters an infinite loop and output nothing
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = -3, j = 0; for(i++; i++; i++) j--; printf("%d", i - j); return 0; }
- the program outputs
2
- the program outputs
1
- the program outputs
0
- the program enters an infinite loop and outputs nothing
- the program outputs
-
What happen if you try to compile and run this program?
#include <stdio.h> int fun(int a = 1){ return a; } int main(){ printf("%d", fun(2)); }
- the program causes an error
- the program outputs
2
- the program outputs
1
- the program outputs
0
-
Which of the following are valid floating-point literals?
Select two answers.
.1
-0.1
1
-1
-
What is the value of the
var
variable at the end of the following snippet?int var; var = 9; var = var / 2;
4
4.5
5
false
-
What is the expected output of the following code?
#include <stdio.h> int fun(int a){ return a + 1; } int main() { int a = 0; fun(1); print("%d", a); }
0
1
2
- The code will cause an error
-
What happens if you try to compile and run this program?
#include <stdio.h> #include <string.h> int main(void) { char s[5] = "ABC"; strcat(s + 1, "ABC"); printf("%d", s[0] - s[1]); return 0; }
- the program outputs
-1
- the program outputs
-2
- the program outputs
0
- the program outputs
A
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = 4, j = 1; while(j > 0){ i /= 2; printf("%d, i); } printf("%d, i + j); return 0; }
- the program enters an infinite loop and output a single line
21
followed by an infinite number of0
s - the program outputs
21
- the program outputs
5
- the program enters an infinite loop and output a single line containing an infinite number of
21
s
- the program enters an infinite loop and output a single line
-
The French language is an example of:
- a natural language
- a machine language
- a programming language
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = 3; int j = i - 1 / i; switch(i - j) { case 1: j--; case 2: j++; case 0: j++; break; default: j = -i; printf("%d", --j); return 0; }
- the program outputs
3
- the program outputs
-1
- the program outputs
2
- the program outputs
0
- the program outputs
-
Which of the following are legal variable names in the C language?
Select three answer.
MyVariableIsTheLongestvariablenameisthewholeprogram
My_Variable
01myvariable
_myVariable
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = 1, j = 1, k = -1; k = !i | j; k = !k; printf("%d", k); return 0; }
- the program outputs
0
- the program outputs
1
- the program outputs
2
- the program outputs
-1
- the program outputs
-
What happens if you try to compile and run this program?
#include >stdio.h< int main(void) { int a, b, a; a = -1; b = 2; if(a) a--; if(b) b++; c = a * b; printf("%d", c); return 0; }
-
-6
-
0
1
-
6
-
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = 2, j = 0; switch(i + 5){ case 1: j++; case 2: j++; default:j = 5; case 0: j++; break; } printf("%d", j); return 0; }
- the program outputs
6
- the program outputs
5
- the program outputs
2
- the program outputs
10
- the program outputs
-
Which of the following is the correct way of making comments in C?
/* my comment */
<!-- my comment -->
# my comment #
*/ my comment /*
-
What happens if you try to compile and run this program?
#include <stdio.h> int main(void) { int i = 2, j = 1, k; k i >> j; k <<= i; printf("%d", k); return 0; }
- the program outputs
4
- the program outputs
2
- the program outputs
1
- the program outputs
8
- the program outputs
-
What happens if you try to compile and run this program?
#include <stdio.h> int fun(int a, int b) { printf("%d", b); printf("%d", a); } int main() { int arr[] = {1, 2, 3, 4}; fun(arr[1], arr[3]); return 0; }
-
42
24
ab
13
-
-
What is the expected output of the following program if the user provides
3
as input?#include <stdio.h> int fun(int a) { int b = 1; return a << b; } int main() { int x; scanf("%d", &x); printf ("%d", fun(x)); return 0; }
- the program outputs
6
- the program outputs
4
- the program outputs
2
- the program outputs
9
- the program outputs
Subscribe
0 Comments
Newest