Ten Technical Interview/Aptitude Questions for you

Ten Technical Interview/Aptitude Questions for you

This article is the first set of Technical questions for your Technical interview/aptitude test. Read and learn!

rn

1. What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

rn

A. The element will be set to 0.

rn

B. The compiler would report an error.

rn

C. The program may crash if some important data gets overwritten.

rn

D. The array size would appropriately grow.

rn

Answer: Option C

rn

Explanation:

rn

If 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.

rn

 

rn

2. What does the following declaration mean?

rn

int (*ptr)[10];

rn

A.ptr is array of pointers to 10 integers

rn

B.ptr is a pointer to an array of 10 integers

rn

C.ptr is an array of 10 integers

rn

D.ptr is an pointer to array

rn

Answer: Option B

rn

 

rn

3. In C, if you pass an array as an argument to a function, what actually gets passed?

rn

A.Value of elements in array

rn

B.First element of the array

rn

C.Base address of the array

rn

D.Address of the last element of array

rn

Answer: Option C

rn

Explanation:

rn

The statement ‘C’ is correct. When we pass an array as a function argument, the base address of the array will be passed.

rn

 

rn

4. What will be the output of the program ?

rn

#include<stdio.h>

rn

int main()

rn

{

rn

    int a[5] = {5, 1, 15, 20, 25};

rn

    int i, j, m;

rn

    i = ++a[1];

rn

    j = a[1]++;

rn

    m = a[i++];

rn

    printf(“%d, %d, %d”, i, j, m);

rn

    return 0;

rn

}

rn

A.2, 1, 15             

rn

B.1, 2, 5

rn

C.3, 2, 15             

rn

D.2, 3, 20

rn

Answer: Option C

rn

Explanation:

rn

Step 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

rn

a[0] = 5, a[1] = 1, a[2] = 15, a[3] = 20, a[4] = 25 .

rn

Step 2: int i, j, m; The variable i,j,m are declared as an integer type.

rn

Step 3: i = ++a[1]; becomes i = ++1; Hence i = 2 and a[1] = 2

rn

Step 4: j = a[1]++; becomes j = 2++; Hence j = 2 and a[1] = 3.

rn

Step 5: m = a[i++]; becomes m = a[2]; Hence m = 15 and i is incremented by 1(i++ means 2++ so i=3)

rn

Step 6: printf(“%d, %d, %d”, i, j, m); It prints the value of the variables i, j, m

rn

Hence the output of the program is 3, 2, 15

rn

 

rn

5. Is there any difference int the following declarations?

rn

int fun(int arr[]);

rn

int fun(int arr[2]);

rn

A.Yes

rn

B.No

rn

Answer: Option B

rn

Explanation:

rn

No, 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.

rn

 

rn

6. Are the expressions arr and &arr same for an array of 10 integers?

rn

A.Yes    

rn

B.No

rn

Answer: Option B

rn

Explanation:

rn

Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints.

rn

 

rn

7. Which of the fplowing statements should be used to obtain a remainder after dividing 3.14 by 2.1?

rn

A.rem = 3.14 % 2.1;

rn

B.rem = modf(3.14, 2.1);

rn

C.rem = fmod(3.14, 2.1);

rn

D.Remainder cannot be obtain in floating point division.

rn

Answer: Option C

rn

Explanation:

rn

fmod(x,y) – Calculates x modulo y, the remainder of x/y.

rn

This function is the same as the modulus operator. But fmod() performs floating point divisions.

rn

 

rn

8. What are the types of pnkages?

rn

A.Internal and External

rn

B.External, Internal and None

rn

C.External and None     

rn

D.Internal

rn

 

rn

Answer: Option B

rn

Explanation:

rn

External pnkage-> means global, non-static variables and functions.

rn

Internal pnkage-> means static variables and functions with file scope.

rn

None pnkage-> means Local variable

rn

 

rn

9. Which of the fplowing special symbp allowed in a variable name?

rn

A.* (asterisk)    

rn

B.| (pipepne)

rn

C.-(hyphen)

rn

D._(underscore)

rn

Answer: Option D

rn

Explanation:

rn

Variable 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.

rn

Examples of vapd (but not very descriptive) C variable names:

rn

=> foo

rn

=> Bar

rn

=> BAZ

rn

=> foo_bar

rn

=> _foo42

rn

=> _

rn

=> QuUx

rn

10. Is there any difference between fplowing declarations?

rn

1 : extern int fun();

rn

2 : int fun();

rn

A.Both are identical

rn

B.No difference, except extern int fun(); is probably in another file

rn

C.int fun(); is overrided with extern int fun();

rn

D.None of these

rn

Answer: Option B

rn

Explanation:

rn

extern 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.

rn

int fun(); declaration in C is to indicate the existence of a function inside the current module or in the same file.

rn

Do tell us if you found these questions useful!

c