Você está na página 1de 7

C Comprehensive Viva Questions

1) What are C tokens ?


Ans: In a passage of text, individual words and punctuation marks are called tokens
or lexical units. Similarly, the smallest individual unit in a c program is known as a
token or a lexical unit. C tokens can be classified as follows:
-Keywords
-Identifiers
-Constants
-Strings
-Special Symbols
-Operators

2) What is the difference between declaring a variable and defining a variable.


Ans: -Whenever we declare a variable then space will not be reserved for the
variable.
-Whenever we declare a variable then compiler will not look for other details
such as definition of the variable.
-Declaration is handy way to write code in which actual memory is not allocated.
struct book {
int pages;
float price;
char *bname;
};

-In the above declaration memory is not allocated. Whenever we define a


variable then memory will be allocated for the variable.
struct book b1;

3) Can I use int data type to store the value 32768? Why?
Ans: No because the range of int is [32767, +32767]

4) What is the difference between the expression ++a and a++?


Ans: ++a is preincrement. means first increments the value then assigned to the
variable.
a++ is postincrement .means after assigning the given value to variable then
the given value can be incremented.
for example:
a=10;
b=++a;
b=11,a=11
b=a++;
b=10,a=11;

5) What is the difference between break and continue?


Ans: -A break causes the switch or loop statements to terminate the moment it is
executed. Loop or switch ends abruptly when break is encountered.
-A continue doesn't terminate the loop, it causes the loop to go to the next
iteration. All iterations of the loop are executed even if continue is encountered. The
continue statement is used to skip statements in the loop that appear after the
continue.

6) When is the void keyword used in a function?


Ans:-When used as a function return type, void means that the function does not
return a value. For example,
void hello (char *name)

{
printf("Hello, %s.", name);
}

-When found in a function heading, void means the function does not take any
parameters. For example,
int init (void)
{
return 1;
}

-Pointers can also be declared as void. They can't be dereferenced without


explicit casting. This is because the compiler can't determine the size of the object
the pointer points to. For example,
int x;
float f;
void *p = &x;

// p points to x

*(int*)p = 2;
p = &r;

// p points to r

*(float*)p = 1.1;

7) What is the difference between Call by Value and Call by Reference?


Ans: CALL BY VALUE:
- value is returned from calling function to called function.by call by value
,sending value of variable cant be changed.
CALL BY REFERENCE:

- adress of value returned from calling function to called function.by call by


reference,sending value of variable can be changed because it is possible to change
the address so the value also changes.

8) What are the advantages of the functions?


Ans:-We can divide c program in smaller modules
-Modular and Structural Programming can be done
-Individual functions can be easily built,tested
-Program development become easyProgram development become easy.

9) What are preprocessor directives?


Ans: In simple terms, a C Preprocessor is just a text substitution tool and it instructs
the compiler to do required pre-processing before the actual compilation.
#define- Substitutes a preprocessor macro.
#include- Inserts a particular header from another file.
#undef- Undefines a preprocessor macro.
#ifdef- Returns true if this macro is defined.
#ifndef Returns true if this macro is not defined.

10) What is Storage class ?what are the different storage classes in c?
Ans: A storage class defines the scope (visibility) and life-time of variables and/or
functions within a C Program. They precede the type that they modify. We have four
different storage classes in a C program
-auto
-register
-static
-extern

11) What do you mean recursion in C ?


Ans: function calling itself.

12) What is the use of a \0 character?


Ans: defines the end of the string.

13) What are pointers? Why are they used?


Ans: pointer points to location of variable .
it stores the adress of variable.

14) What is a dangling pointer?


Ans:which pointer variable pointing to a inactive or deadlocation.

15) What is the use of void pointer and null pointer in C language?
Ans:NULL POINTER:
-A pointer that is assigned NULL is called a null pointer.
-pointer variable in case you do not have an exact address to be assigned.

VOID POINTER:

-We have declared 3 variables of integer,character and float type.


-When we assign address of integer to the void pointer, pointer will become
Integer Pointer.
-When we assign address of Character Data type to void pointer it will become
Character Pointer.
-Similarly we can assign address of any data type to the void pointer.
-It is capable of storing address of any data type

16) What is an array of pointers?


Ans:pointer to array or array of pointers.means it stores the address of array
variable.
ex: int arr[]={1,2,3};
int *arr1[];
*arr1=arr;
arr1[0]=1
arr1[1]=2 arr1[2]=3

17) Difference between array name and a pointer variable?


Ans:

18) Define function pointer?


19) What are the differences between structures and union?
Ans: structure and unions are same .both forms collection of diff datatypes into a
single entity.
diff is size of structure is equal to sum of sizes of datatypes used in structure but
size of union is highest size of datatype .

20) Is it possible to pass an entire structure to functions?


Ans: yes

21) Explain Union. What are its advantages?


Ans:-forms collection of diff datatypes into a single entity.
-size of union is highest size of datatype .

-advantage is usage of memory can be decreased.

22) What are the differences between structures and arrays?


Ans:- Array elements are homogeneous. Structure elements are of different data
type.
- Array allocates static memory and uses index / subscript for accessing elements
of the array. Structures allocate dynamic memory and uses (.) operator for
accessing the member of a structure.
- Array is a pointer to the first element of it. Structure is not a pointer
- Array element access takes less time in comparison with structures.

23) What is the use of typedef?


Ans: The purpose of typedef is to assign alternative names to existing types

24) What is the purpose of ftell?


Ans: ftell function returns the current file position indicator for the stream pointed to
by stream.
long int ftell(FILE *stream);

25) What is the difference between calloc() and malloc() ?


Ans:-using calloc() we can create the memory dynamically at intial stage.
-using realloc() we can create the memory dynamically at middle stage of
process.

Você também pode gostar