C Programming Interview Question and Answer SET 6





101. What is the difference between %d and %*d in c language?
%d give the original value of the variable and %*d give the address of the variable.
eg:-int a=10,b=20;
printf("%d%d",a,b);
printf("%*d%*d",a,b);
Result is 10 20 1775 1775 .Here 1775 is the starting address of the memory allocation for the integer.a and b having same address because of contagious memory allocation.

102. How does a C program come to know about command line arguments?
 When we execute our C program, operating system loads the program into memory. In case of DOS, it first loads 256 bytes into memory, called program segment prefix. This contains file tables,environment segment, and command line information. When we compile the C program the compiler inserts additional code that parses the command, assigning it to the argv array, making the arguments easily accessible within our C program.

103. How are pointer variables initialized?
 Pointer variable are initialized by one of the following two ways
- Static memory allocation
- Dynamic memory allocation

104. What is modular programming?
If a program is large, it is subdivided into a number of smaller
programs that are called modules or subprograms. If a complex
problem is solved using more modules, this approach is known as
modular programming

105. Where does global, static, local, register variables and C Program instructions get stored?
Global , static, local :  In main memory        
Register variable: In registers
C program : In main memory.

106. Where are the auto variables stored?
Auto variables are stored in main memory and their default value is a garbage value.

107. What is an lvalue?
An lvalue is an expression to which a value can be assigned. The lvalue
expression is located on the left side of an assignment statement,
whereas an rvalue is located on the right side of an assignment
statement. Each assignment statement must have an lvalue and an
rvalue. The lvalue expression must reference a storable variable in
memory. It cannot be a constant

108. What is an argument? Differentiate between formal arguments and actual arguments?
An argument is an entity used to pass the data from calling function to
the called function. Formal arguments are the arguments available in
the function definition. They are preceded by their own data types.
Actual arguments are available in the function call.

109. When is a switch statement better than multiple if statements?
A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

110. Differentiate between a linker and linkage?
A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the
linkage of variable.

111. Define Operator, Operand, and Expression in 'C'?
Operators are symbols which take one or more operands or expressions and perform arithmetic or logical computations.
Operands are variables or expressions which are used in operators to evaluate the expression.
Combination of operands and operators form an expression.

112. What will be the result of the following code?
#define TRUE 0 // some code
while(TRUE)
{
    // some code
}
Answer: This will not go into the loop as TRUE is defined as 0.

113. What will be printed as the result of the operation below:
main()
{
    int a=0;
    if(a==0)
        printf(“Cisco Systemsn”);
        printf(“Cisco Systemsn”);
}
Answer: Two lines with “Cisco Systems” will be printed.

114. Do you know pragma directives in c?
Pragma is implementation specific directive i.e each pragma directive has different implementation rule and use. If compiler does not recognize particular pragma it simply ignore that pragma statement without showing any error or warning message and execute the whole program assuming this pragma statement is not present.

115. Predict the output or error
main()
{
clrscr();
}
clrscr();
Ans:No output/error
Explanation:The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).

116. Predict the output or error
enum colors {BLACK,BLUE,GREEN}
 main()
{

 printf("%d..%d..%d",BLACK,BLUE,GREEN);

 return(1);
}
Answer: 0..1..2
Explanation: enum assigns numbers starting from 0, if not explicitly defined.

117. Predict the output or error
 main()
{
int i;
printf("%d",scanf("%d",&i));  // value 10 is given as input here
}
Answer:1
Explanation: Scanf returns number of items successfully read and not 1/0.  Here 10 is given as input which  should have been scanned successfully. So number of items read is 1.

118. what will be the position of the file marker?
            a: fseek(ptr,0,SEEK_SET);
            b: fseek(ptr,0,SEEK_CUR);
Ans: a: The SEEK_SET sets the file position marker to the starting of the file.
        b: The SEEK_CUR sets the file position marker to the current position
            of the file.

119. Predict the output or error
main()
            {
            main();
            }
Ans: Runtime error : Stack overflow.
Explanation: main function calls itself again and again. Each time the function is called its return address is stored in  the call stack. Since there is no condition to terminate the function call, the call stack overflows at runtime. So it terminates the program and results in an error.

120. Predict the output or error
main()
{
              int i=5,j=6,z;
              printf("%d",i+++j);
             }
Answer:11
Explanation:the expression i+++j is treated as (i++ + j)    

Comments

Popular posts from this blog

Tips 01) self introduction in an interview

Computer Science Terminology

Why Failure Is Good for Success