Wednesday, October 24, 2007

C interview Questions

1 Diffence arrays and pointers?
Arays may be defined as the containers we can store more than one datatypes

Pointers contains the address of the datatypes stored

2 What is static memory allocation and dynamic memory allocation?

When the memory is allocated before compilation than it is said to be allocated statically whereas when the memory is allocated at the runtime then it is said to be allocated dynamically.

3 How are pointer variables initialized?

pointer variables are initialized when the values for which it is a pointer is called.


4 What is the purpose of realloc( )?
This function is used to reallocate the memory deleted


5 Are pointers integers?
pointers are variables


6 What is a pointer variable?
When the value of the variable changes its address also changes so the pointers to the variables are said to be pointer variables.

7 What is a pointer value and address?

Pointer value gives the value of the variable, whereas pointer address gives the address where the variable is stored

8 what is a method?
method is defined as afun defined in class )


9 What is the purpose of main( ) function?
main() function returns a integer value for the exit of the program


10 What are the advantages of the functions?

by using the functions we can divide a program into smaller units so that it is easy to maintain a program and it also returns the value which can be used as arguments

11 What is an argument ? differentiate between formal arguments and actual
arguments?

arguments are the values which are passed to the function as input , formal arguments are those

which gets the address of the values whereas actual arguments gets the actual values.

12 What is a function and built-in function?

built-in functions are those which are provide by the c++ library


13 Differentiate between a linker and linkage?

14 When does the compiler not implicitly generate the address of the first element of an array?
because the pointer is not initiated at that time


15 What are the characteristics of arrays in C?

in arrays of c we can store a lot of same data of any datatype.


16 What is modular programming?

by the term modular programming we mean dividing the program into modules so that all the process goes systematically.

17 What is storage class and what are storage variable ?

18 What are advantages and disadvantages of external storage class?

19 Differentiate between an internal static and external static variable?
when the static variable is declared within a class then it is said to internal static variable and when the static variable is declared outside a class then it is said to be external static variable

20 What are the advantages of auto variables?
advantage of auto variable is that it automatically get initialized when called and automatically destroyed when the function exits.

21 Differentiate between an external variable definition and external variable declaration

when we declare the type of the variable outside any class or function then it is said to be external variable declared and when it is initialized to some value then it is said to be defined

22 Which expression always return true? Which always return false?

23 Write the equivalent expression for x%8?
X%=8

24 why n++ executes faster than n+1?
Because n+1 have to assign its value to some var whereas value of n++ can be directly used

25 what is a modulus operator? What are the restrictions of a modulus operator?

26 How do you print an address?
by using the reference operator in front of the var whose address we want to know

27 Is using exit() the same as using return?
no because exit function terminates the program whereas return() function returns the pointer to the next line where it has left before

28 Is it better to use a pointer to navigate an array of values,or is it better to use a subscripted array name?
it is better to use pointer to navigate an array of values


29 Can the sizeof operator be used to tell the size of an array passed to a function?
yes the sizeof operator can be used to tell the size of an array

30 Is it possible to execute code even after the program exits the main() function?
no we cant execute the code after the program exits te main program

31 What is a static function?
static function is the one which retains its value through out the program

32 Why should I prototype a function?
Prototype of a function is used for the strong type checking while compiling



33 What is the difference between a string and an array?
in a string the value stored is type character only whereas in an array we can store any type of datatype

34 Can math operations be performed on a void pointer?
no

35 How can you determine the size of an allocated portion of memory?
by using the memsize() function

36 What is a “null pointer assignment” error? What are bus errors, memory faults, and core dumps?


37 What is the difference between NULL and NUL?

38 What is the heap?
Heap is the place from where memory is allocated to the variables and s returned when deleted

39 Why should we assign NULL to the elements (pointer) after freeing them?
we should assign the value NULL to the elements after freeing them because if we don’t do this then we can free it again by mistake and can result In error.

40 What is a null pointer?
when the pointer doesn’t contains any value then it is said to be a null pointer


41 When should a far pointer be used?

42 Can the size of an array be declared at runtime?
Yes, the size of an array can be declared at runtime.

43 What is the stack?
Stack is a sort of data-structure where we can store data of any data type and which works on the principle of lifo(last in first out) it means the data inserted in the last will be out first.

44 What is the difference between far and near?

45 When would you use a pointer to a function?

46 How do you use a pointer to a function?

47 Can you add pointers together? Why would you?

48 What does it mean when a pointer is used in an if statement?


49 Is NULL always defined as 0?

50 What is a void pointer?
when the return type of the function is not known then it is safe to use void pointer.

51 Is it better to use malloc() or calloc()?


52 How many levels of pointers can you have?
There are two levels of pointers one level is when it is declared and the another level is when it is initialized

53 What is indirection?

54 How do you print only part of a string?

55 How can I convert a string to a number?
yes we can convert a string to number

56 How can I convert a number to a string?
By using the typecast operator by converting its data type to int.

57 What is #line used for?
#line is used for the preprocessor directives.

58 What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
By using the strcpy we can copy one string to another string and in a memcopy we can copy a part of the memory

59 How can you check to see whether a symbol is defined?


60 How do you override a defined macro?
we can override a defined macro by defining the macro again in the code

61 What is a pragma?
Pagma is used for the export of data from one system to another

62 What are the standard predefined macros?
standard predefined macros are the one which are already defined in the library.

63 How can type-insensitive macros be created?
type-insensitive macros can be created by using the template function

64 How many levels deep can include files be nested?

65 Can include files be nested?
Yes include files can be included.

66 Can you define which header file to include at compile time?
when u use define pre-defined functions or operators in a program then we use those header files which contains these functions or operators.

67 What is the difference between #include and #include “file”?

When we use #include then the compiler searches for the file at the default address only but when we use #include ”file” then it searches for the whole.



68 Is it better to use a macro or a function?
it is better to use a function rather then a macro




69 What is the benefit of using an enum rather than a #define constant?
benefit of using enum rather then #defined is that by enum a list is created





70 What is the benefit of using #define to declare a constant?
the use of #define is that the memory is pre-allocated when we use #define





71 How are portions of a program disabled in demo versions?





72 Can a file other than a .h file be included with #include?
yes a file other than a.h can be included




73 How can you avoid including a header more than once?





74 What will the preprocessor do for a program?
the preprocessor substitutes the preprocessor directives into there respective positions




75 What is the difference between text and binary modes?
when we stores some data in the file then it can be stored in the binary modes i.e in 0’s or 1’s when stored in the tis it is said to be stored in binary mode. Binary mode generally uses less space as compared to the text mode


76 How can I search for data in a linked list?
in the linked list the address of the next node is given in the previous node thus by we can search data by the help of the addresses in a linked list.

77 What is a macro, and how do you use it?
macro is a subprogram whose code goes into the calling program when called. we can use it by using it as a preprocessor directive.


78 What is Preprocessor?
preprocessor is the one which calls the include files and allocates them to the required positon. It also allocates memory for #define memory variables.




79 How do you determine whether to use a stream function or a low-level function?





80 How can I open a file so that other programs can update it at the same time?



81 How can you restore a redirected standard stream?


.


82 How do you redirect a standard stream?





83 How can I make sure that my program is the only one accessing a file?



84 How can I sort a linked list?





85 How can you determine the maximum value that a numeric variable can hold?
by the datatype of the numeric value i.e it may be int. long, float etc




86 What is the quickest searching method to use?
Merge sort




87 What is the easiest searching method to use?
Bubble sort




88 What is the difference between declaring a variable and defining a variable?
in declaring a var we only gives the declaration of the datatype whereas by defining the var we initializes the value of the var.



89 What is the quickest sorting method to use?
Merge sort




90 What is the easiest sorting method to use?
the easiest sorting method to use is bubble sort




91 What is the benefit of using const for declaring constants?
when we want not to change the value of the var or function throughout the program then we use const



92 Can static variables be declared in a header file?
No static variable cant be declared in a header file.




93 What is hashing?



94 Is it acceptable to declare/define a variable in a C header?





95 When should a type cast not be used?
when we have to convert a small size var to a big size variable.




96 When should a type cast be used?
typecast should be used when we have to save the space




97 How can I sort things that are too large to bring into memory?




98 How reliable are floating-point comparisons?
It gives the exact values.




99 Can a variable be both const and volatile?
No a variable cant be both const and volatile




100 when should the volatile modifier be used?





101 When should the register modifier be used? Does it really help?





102 What is a const pointer?
const pointer is the pointer to the constant value.




103 What is page thrashing?





104 Array is an lvalue or not?





105 What is an lvalue?





106 What is the difference between goto and longjmp() and setjmp()?





107 When is a switch statement better than multiple if statements?
Switch statement is better than multiple if statements when we have to select a statement.

1 comment:

Anonymous said...

Thanks for posting the very much useful interview questions. Cant stop appreciating ur effor. Probably add a note that peopl should take answers with pinch of salt. Some answers are wrong :-)