Samsung Previous Years Solved Sample Placement Papers
-
If `abc` is the input, then the following program fragment:
`char x, y, z; printf("%d", scanf("%c%c%c", &x, &y, &z));`
Results in:
(a) A syntax error
(b) A fatal error
(c) Segmentation violation
(d) Printing of 3 Answer: Option D
- Solution: The `scanf` function successfully reads three characters and returns 3, indicating the number of inputs processed.
-
Consider the statements:
`putchar(getchar()); putchar(getchar());`
If `ab` is the input, the output will be:
(a) An error message
(b) This can’t be input
(c) ab
(d) a b Answer: Option C
- Solution: The first `getchar` reads 'a', and the second `getchar` reads 'b', which are printed in sequence.
-
The operators `.`, `||`, `<`, `=` arranged in ascending order of precedence:
(a) ., ||, <, =
(b) =, <, ||, .
(c) =, ||, <, .
(d) <, ||, =, . Answer: Option A
- Solution: Operator precedence in C dictates that `.` has the highest precedence, followed by `<`, `||`, and `=`.
-
The following program fragment:
`unsigned i = -1; int j = -4; printf("%u", i + j);`
Prints:
(a) Garbage
(b) -3
(c) An integer that changes from machine to machine
(d) None of the above Answer: Option A
- Solution: The value of `-1` is interpreted as the maximum value of an unsigned integer, causing undefined behavior and garbage output.
-
The following program fragment:
`for (i = 3; i < 15; i += 3); printf("%d", i);`
Results in:
(a) A syntax error
(b) An execution error
(c) Printing of 12
(d) Printing of 15 Answer: Option D
- Solution: The loop increments `i` to 15, exiting the loop, and prints the final value of `i` as 15.
-
In the following program, identify the incorrect statement:
`int main(void) { int i = 100; int *pi = &i; int **dpi = pi; }`
(a) dpi to store a pointer with the address for pi is a double pointer
(b) (*pi == i) is true.
(c) (*pi == **dpi) is true.
(d) (*dpi == 100) is true Answer: Option D
- Solution: `(*dpi)` is expected to point to the address of `pi`, not the value 100. Hence, Option D is incorrect.
-
Consider the following program fragment:
`int counter = 0, i; for (i = 0;; i++) { if (i < 100) continue; counter++; if (counter == 100) break; } printf("%d %d", i, counter);`
Results in:
(a) 199 100
(b) 200 100
(c) 199 99
(d) 200 0 Answer: Option A
- Solution: The loop iterates until `i` is 199 and `counter` reaches 100, making the output `199 100`.
-
Consider the array definition:
`int a[] = {10, 20, 30, 40};`
Identify the incorrect statement:
(a) Successive one-dimensional array elements in the array a[1], a[2] are located in contiguous memory space.
(b) a[1] and *(a+1) are the same.
(c) During initialization, array size must be specified; otherwise, a compile-time error occurs.
(d) &a[1] which has a+1 value, such as the address Answer: Option C
- Solution: An array can be initialized without specifying its size explicitly, as the size is inferred from the initializer.
-
Define `sqrt(x) x*x`
`sqrt(3-5);`
Results in:
Answer: -17
- Solution: The macro `sqrt(x)` expands to `(3-5)*(3-5)`, evaluating to `-17` due to incorrect usage of parentheses.
-
Define `true 1`, `false -1`, `null 0`:
The program:
`if(null) printf("..."); else if(false) printf("true");`
Results in:
Answer: True
- Solution: Since `null` is 0 (false), the condition falls to the `else if`, where `false (-1)` is treated as true.
-
The program fragment:
`int i = 10; switch (i) { printf("samsung"); case 10: printf("some string"); break; case 5*2: printf("some string"); break; }`
Results in:
Answer: Error due to conflicting case
- Solution: The case `10` and `5*2` conflict, causing a compilation error.
-
The program fragment:
`int i = 5, *j; void *k; k = j = &i; printf("%d", k + 1);`
Results in:
Answer: Compilation error
- Solution: Arithmetic operations are not allowed on `void` pointers unless explicitly cast, causing a compilation error.