Social Icons

Monday, December 10, 2012

C LANGUAGE INTERVIEW PAPERS ANSWERS & QUESTIONS


58.Write a program which employs Recursion ?
Ans:
int fact(int n) { return n > 1 ? n * fact(n - 1) : 1; }

59.Write a program which uses Command Line Arguments?
Ans:
#include
         #include
         void main(int argc,char *argv[])
                          {
                           int i;
                           clrscr();
                           for(i=0;i                            printf("\n%d",argv[i]);
                           }


60.Difference between array and pointer ?
Ans: Array Vs Pointer
1- Array allocates space automatically
2- It cannot be resized
3- It cannot be reassigned
4- sizeof (arrayname) gives the number of bytes occupied by the array.
 1-Explicitly assigned to point to an allocated space.
2-It can be sized using realloc()
3-pointer can be reassigned.
4-sizeof(p) returns the number of bytes used to store the pointer variable p.


61.what do the 'c' and 'v' in argc and argv stand for?
Ans:
The c in argc (argument count) stands for the number of command line argument the program is invoked with and v in argv (argument vector) is a pointer to an array of character string that contain the arguments.


62.What are C tokens ?
Ans: T
here are six classes of tokens: identifier, keywords, constants, string literals, operators and
other separators.


63.What are C identifiers?
Ans:
These are names given to various programming element such as variables, function, arrays.
It is a combination of letter, digit and underscore.
It should begin with letter. backspace is not allowed.


64.Difference between syntax Vs logical error?
Ans:
Syntax Error Vs Logical Error
1-These involves validation of syntax of language.
2-compiler prints diagnostic message.
1-logical error are caused by an incorrect algorithm or by a statement mistyped in such a way
that it doesn’t violet syntax of language.
2-difficult to find.


65.What is preincrement and postincrement ?
Ans: ++n (pre increment) increments n before it’s value is used in an assignment operation or any
expression containing it. n++ (post increment) does increment after the value of n is used. 


66.Write a program to interchange 2 variables without using the third one.
Ans:
a ^= b; ie a=a^b
b ^= a; ie b=b^a;
a ^= b ie a=a^b;
here the numbers are converted into binary and then xor operation is performed.
You know, you’re just asking “have you seen this overly clever trick that’s not worth applying on
modern architectures and only really applies to integer variables?” 


67.What is the maximum combined length of command line arguments including the space between adjacent arguments?
Ans: It depends on the operating system.


68.What are bit fields? What is the use of bit fields in a Structure declaration?
Ans: A bit field is a set of adjacent bits within a single implementation based storage unit that we
will call a "word". The syntax of field definition and access is based on structure.
struct {
unsigned int k :1;
unsigned int l :1;
unsigned int m :1;
}flags;
the number following the colon represents the field width in bits.
Flag is a variable that contains three bit fields.


69.What is a preprocessor, What are the advantages of preprocessor ?
Ans: A preprocessor processes the source code program before it passes through the compiler.
1- a preprocessor involves the readability of program
2- It facilitates easier modification
3- It helps in writing portable programs
4- It enables easier debugging
5- It enables testing a part of program
6- It helps in developing generalized program


70.what are the facilities provided by preprocessor ?
Ans:
1-file inclusion
2-substitution facility
3-conditional compilation


71.What are the two forms of #include directive ?
Ans:
1.#include "filename"
2.#include
the first form is used to search the directory that contains the source file. If the search fails in the home directory it searches the implementation defined locations. In the second form ,the preprocessor searches the file only in the implementation defined locations.


72.How would you use the functions randomize() and random()?
Ans:
Randomize() initiates random number generation with a random value.
Random() generates random number between 0 and n-1;


73.What do the functions atoi(), itoa() and gcvt() do?
Ans:
atoi() is a macro that converts integer to character.
itoa() It converts an integer to string
gcvt() It converts a floating point number to string


74.How would you use the functions fseek(), freed(), fwrite() and ftell()?
75.What is the difference between the functions memmove() and memcpy()? 

Ans: The arguments of memmove() can overlap in memory. The arguments of memcpy() cannot.

76.What is a file ?
Ans: A file is a region of storage in hard disks or in auxiliary storage devices. It contains bytes of
information. It is not a data type.


77. What are the types of file?
Ans: Files are of two types
1-high level files(stream oriented files) :These files are accessed using library functions
2-low level files(system oriented files) :These files are accessed using system calls

No comments:

Post a Comment