Ten Technical Interview/Aptitude Questions for you – Set 7

Ten Technical Interview/Aptitude Questions for you – Set 7

Question 1: Is there any difference int the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);

rn

1. True

rn

2. False

rn

Answer: Option 1

rn

Yes, we have to specify the data type of the parameter when declaring a function.

rn

Question 2: Suppose a program is divided into three files f1, f2 and f3, and a variable is defined in the file f1 but used in files f2 and f3. In such a case would we need the extern declaration for the variables in the files f2 and f3?

rn

1. True

rn

2. False

rn

Answer: Option 1

rn

Yes, Consider,

rn

variable f1 in FILE1.C
variable f2 in FILE2.C
variable f3 in FILE3.C

rn

If we need to use the variable f1 in the files FILE2.C and FILE3.C
we have to declare the variable f1 as extern int f1; in the files FILE2.C and FILE3.C.

rn

Question 3: Global variable are available to all functions. Does there exist a mechanism by way of which it available to some and not to others.

rn

1. True

rn

2. False

rn

Answer: Option 2

rn

The only way this can be achieved is to define the variable locally in main() instead of defining it globally and then passing it to the functions which need it.

rn

Question 4: Is it true that a global variable may have several declarations, but only one definition?

rn

1. True

rn

2. False

rn

Answer: Option 1

rn

Yes, in all the global variable declarations, you need to use the keyword extern.

rn

Question 5: Is it true that a function may have several declarations, but only one definition?

rn

1. True

rn

2. False

rn

Answer: Option 1

rn

Yes, but the function declarations must be identical.

rn

Question 6: How many times the while loop will get executed if a short int is 2 byte wide?

rn

#include<stdio.h>

rn

int main()

rn

{

rn

    int j=1;

rn

    while(j <= 255)

rn

    {

rn

        printf(“%c %dn”, j, j);

rn

        j++;

rn

    }

rn

    return 0;

rn

}

rn

1.Infinite times

rn

2. 255 times

rn

3. 256 times

rn

4. 254 times

rn

Answer: Option 2

rn

The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop.  

rn

Question 7: Which of the following is not logical operator?

rn

1. &

rn

2. &&

rn

3. ||

rn

4. !

rn

Answer: Option 1

rn

Bitwise operators:
& is a Bitwise AND operator.

rn

Logical operators:
&& is a Logical AND operator.
|| is a Logical OR operator.
! is a NOT operator.

rn

So, ‘&’ is not a Logical operator.

rn

Question 8: In mathematics and computer programming, which is the correct order of mathematical operators?

rn

1 .Addition, Subtraction, Multiplication, Division

rn

2. Division, Multiplication, Addition, Subtraction

rn

3. Multiplication, Addition, Division, Subtraction

rn

4. Addition, Division, Modulus, Subtraction

rn

Answer: Option 2

rn

Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction).

rn

Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, and Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS.

rn

Question 9: Which of the following cannot be checked in a switch-case statement?

rn

1. Character

rn

2. Integer

rn

3. Float

rn

4. enum

rn

Answer: Option 3

rn

The switch/case statement in the c language is defined by the language specification to use an int value, so you cannot use a float value.

rn

Question 10: Point out the error, if any in the program.

rn

#include<stdio.h>

rn

int main()

rn

{

rn

    int i = 1;

rn

    switch(i)

rn

    {

rn

        printf(“This is c program.”);

rn

        case 1:

rn

            printf(“Case1”);

rn

            break;

rn

        case 2:

rn

            printf(“Case2”);

rn

            break;

rn

    }

rn

return 0;

rn

}

rn

1. Error: No default specified

rn

2. Error: Invalid printf statement after switch statement

rn

3. No Error and prints “Case1”

rn

4. None of above

rn

Answer: Option 3

rn

switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints “Case1”.

rn

printf(“This is c program.”); is ignored by the compiler.

rn

Hence there is no error and prints “Case1”.

c