ads

Mostly asked C questions in TCS interview | Interview C questions | TCS interview questions | Learningstudio

Some of the C interview questions are listed below


Ques.1 A pointer variable can be

1. Changed within function.

2. Assigned an integer value.

3. None of these

4. Passed to a function as argument.

Correct Op: 4 Passed to a function as argument.


Question: 2 Which of the following uses structure?

1. Linked Lists

2. Array of structures

3. All of these

4. Binary Tree

Correct Op: 3 All of these

Question:3. Strings are character arrays. The last index of it contains the null-terminated character

1. \t

2.\1

3.\0

4. \n

Correct Op:3.\0

Ques. 4 Which of the following is a collection of different data types?

1. String

2. Structure

3. Array

4. Files

Corect Op: 2. Structure

Ques. 5 What funetion should be uscd to free the memory allocated by calloc() ?

1. frec();

2. malloc(variable_name, 0)

3. dealloc():

4. memalloc(variable _name, 0)

Corect Op:1

Ques. 6 In the standard library of C programming language, which of the following header file is designed for basic mathematical operations?

1.conio.h

2.stdio.h

3.math.h

4.Dos.h

Correct Op: 3 math.h

Ques. 7 int **ptr; is?

1. Pointer to integer

2. None of these

3. Pointer to pointer

4. Invalid declaration

Correct Op:3 Pointer to pointer

Ques. 8 Which of the following special symbol allowed in a variable name?

1._ (underscore)

2. -(hyphen)

3. | (pipeline)

4. * (asterisk)

Correct Op: 1 _(underscore)

Ques. 9 What will happen if in a C program you assign a value to an array element whose subscript exceeds the

size of array?

1. The element will be set to 0.

2. The compiler would report an error.

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

4. The array size would appropriately grow.

Answer: Option 3 Explanation:

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.


Ques. 10 What should the program below print?

#include <stdio.h>

#include <string.h> #include <stdlib.h>

void myfunc(char** param){

++param;

}

int main() {

char* string = (char*)malloc(64); strcpy(string, "hello_World");

myfunc(&string); myfunc(&string):

printf("%s\n", string);

//ignore memory leak for sake of quiz return 0;

}

1. hello_World

2. ello_Wold

3. lo_World

4. llo_World

Correct Op: hello_World


Ques. 11 What is the output of this C code?

#include <stdio.h>

void main()

{

int k= 5; int *p= &k;

int **m= &p: printf("%d%d%d\n", k, *p, **p);

}

a.555

b. 55junk

C. 5 junk junk

d. Compile time error

Correct op: D Explanations

o It would have been 555ifit were **m and not **p.


Ques. 12 Which of the following statements about stdout and stderr are true?

a. They both are the same

b. Run time errors are automatically displayed in stderr

C. Both are connected to the screen by default.

d. stdout is line bufřered but stderr is unbuffered.

Correct Op: D. stdout is line bufřered but stderr is unbuffered.


Ques. 13 Given the below statements about C programming language:

1. main() function should always be the first fiunction present in a C program file

2. all the elements of an union share their memory  location

3. A void pointer can hold address of any type and can be typcasted to any typpe

4. A static variable hold random junk value if it is not initialised

Which of the above are correct statements

A) 2,3

B) 1,2

C)1,2,3

D) 1,2,3,4

Corect Op - A. 2,3

 Explanations

In a file you can write a function before main() - False

all the elenments of an union share their memory location - True.

A void pointer can hold address of any type and can be typcasted to any type - Tue

Static value - False as valuc is 0

In C, if an object that has static storage duration is not initialized explicitly, then:

if it has pointer type, it is initialized to a NULL pointer;

o if it has arithmetic type, it is initialized to (pasitive or unsigned) zero;

o if it is an aggregate, every member is initialized (recursively) according to these rules;

if it is a union, the first named member is initialized (recursively) according to these rules.


Ques. 14 If a function is defined as static, it means

a. The value returned by the function does not change

b. all the variable declared inside the function automatically will be assigned initial value of zero

C. It should be called only within the same source code / program file.

d. None of the other choices as it is wrong to add static prefix to a function

Correct Op: C It should be called only within the same source code / program file.

Access to static functions is restricted to the file where they are declared. Therefore, when we want to restrict access to functions, we make them static.


Ques. 15 Comment on the below while statement

while (0 == 0) {

1. It has syntax error as there are no statements within braces }

2. It will run forever

3. It compares 0 with 0 and since they are equal it will exit the loop immediately

4. It has syntax error as the same number is being compared with itself

Correct Op:2 It will run forever

while( 0)==0) {} is equivalent to while(1) {}


Post a Comment

0 Comments