Sunday, 23 September 2012

C Inteview Questions-6


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: There 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
1-These involves validation of syntax of language.
2-compiler prints diagnostic message.
Logical Error
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 post increment?
Ans: ++n (pre increment) increments n before its 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

No comments:

Post a Comment