This article is the first set of Technical questions for your Technical interview/aptitude test. Read and learn!
rn1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?
rnA. The element will be set to 0.
rnB. The compiler would report an error.
rnC. The program may crash if some important data gets overwritten.
rnD. The array size would appropriately grow.
rnAnswer: Option C
rnExplanation:
rnIf the index of the array size is exceeded, the program will crash. Hence “option c” is the correct answer. But the modern compilers will take care of this kind of errors.
rnrn
2. What does the following declaration mean?
rnint (*ptr)[10];
rnA.ptr is array of pointers to 10 integers
rnB.ptr is a pointer to an array of 10 integers
rnC.ptr is an array of 10 integers
rnD.ptr is an pointer to array
rnAnswer: Option B
rnrn
3. In C, if you pass an array as an argument to a function, what actually gets passed?
rnA.Value of elements in array
rnB.First element of the array
rnC.Base address of the array
rnD.Address of the last element of array
rnAnswer: Option C
rnExplanation:
rnThe statement ‘C’ is correct. When we pass an array as a function argument, the base address of the array will be passed.
rnrn
4. What will be the output of the program ?
rn#include<stdio.h>
rnint main()
rn{
rnint a[5] = {5, 1, 15, 20, 25};
rnint i, j, m;
rni = ++a[1];
rnj = a[1]++;
rnm = a[i++];
rnprintf(“%d, %d, %d”, i, j, m);
rnreturn 0;
rn}
rnA.2, 1, 15
rnB.1, 2, 5
rnC.3, 2, 15
rnD.2, 3, 20
rnAnswer: Option C
rnExplanation:
rnStep 1: int a[5] = {5, 1, 15, 20, 25}; The variable arr is declared as an integer array with a size of 5 and it is initiapzed to
rna[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .
rnStep 2: int i, j, m; The variable i,j,m are declared as an integer type.
rnStep 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2
rnStep 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.
rnStep 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3)
rnStep 6: printf(“%d, %d, %d”, i, j, m); It prints the value of the variables i, j, m
rnHence the output of the program is 3, 2, 15
rnrn
5. Is there any difference int the following declarations?
rnint fun(int arr[]);
rnint fun(int arr[2]);
rnA.Yes
rnB.No
rnAnswer: Option B
rnExplanation:
rnNo, both the statements are same. It is the prototype for the function fun() that accepts one integer array as an parameter and returns an integer value.
rnrn
6. Are the expressions arr and &arr same for an array of 10 integers?
rnA.Yes
rnB.No
rnAnswer: Option B
rnExplanation:
rnBoth mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints.
rnrn
7. Which of the fplowing statements should be used to obtain a remainder after dividing 3.14 by 2.1?
rnA.rem = 3.14 % 2.1;
rnB.rem = modf(3.14, 2.1);
rnC.rem = fmod(3.14, 2.1);
rnD.Remainder cannot be obtain in floating point division.
rnAnswer: Option C
rnExplanation:
rnfmod(x,y) – Calculates x modulo y, the remainder of x/y.
rnThis function is the same as the modulus operator. But fmod() performs floating point divisions.
rnrn
8. What are the types of pnkages?
rnA.Internal and External
rnB.External, Internal and None
rnC.External and None
rnD.Internal
rnrn
Answer: Option B
rnExplanation:
rnExternal pnkage-> means global, non-static variables and functions.
rnInternal pnkage-> means static variables and functions with file scope.
rnNone pnkage-> means Local variable
rnrn
9. Which of the fplowing special symbp allowed in a variable name?
rnA.* (asterisk)
rnB.| (pipepne)
rnC.-(hyphen)
rnD._(underscore)
rnAnswer: Option D
rnExplanation:
rnVariable names in C are made up of letters (upper and lower case) and digits. The underscore character (“_”) is also permitted. Names must not begin with a digit.
rnExamples of vapd (but not very descriptive) C variable names:
rn=> foo
rn=> Bar
rn=> BAZ
rn=> foo_bar
rn=> _foo42
rn=> _
rn=> QuUx
rn10. Is there any difference between fplowing declarations?
rn1 : extern int fun();
rn2 : int fun();
rnA.Both are identical
rnB.No difference, except extern int fun(); is probably in another file
rnC.int fun(); is overrided with extern int fun();
rnD.None of these
rnAnswer: Option B
rnExplanation:
rnextern int fun(); declaration in C is to indicate the existence of a global function and it is defined externally to the current module or in another file.
rnint fun(); declaration in C is to indicate the existence of a function inside the current module or in the same file.
rnDo tell us if you found these questions useful!