Tuesday, November 2, 2010

INTERVIEW QUESTIONS IN C : 1


1.Which of the following statements are correct about the below program?
#include
int main()
{
    int i = 0;
    i++;
    if(i <= 5)
    {
        printf("IndiaBIX\n");
        exit();
        main();
    }
    return 0;
}
A.
The program prints 'IndiaBIX' 5 times
B.
The program prints 'IndiaBIX' one time
C.
The call to main() after exit() doesn't materialize.
D.
The compiler reports an error since main() cannot call itself.
Answer: Option B
Explanation:
Step 1int i = 0; here variable i is declared as an integer type and initialized to '0'(zero).
Step 2i++; here variable i is increemented by 1(one). Hence, i = 1
Step 3if(i <= 5) becomes if(1 <= 5) here we are checking '1' is less than or equal to '5'. Hence the if condition is satisfied.
Step 4printf("IndiaBIX\n"); It prints "IndiaBIX"
Step 5exit(); terminates the program execution.
Hence the output is "IndiaBIX".
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
2.What will be the output of the program?
#include
int main()
{
    float a=0.7;
    if(a < 0.7f)
        printf("C\n");
    else
        printf("C++\n");
    return 0;
}
A.
C
B.
C++
C.
Compiler error
D.
Non of above
Answer: Option B
Explanation:
if(a < 0.7f) here a is a float variable and 0.7f is a float constant. The float variable a is not less than 0.7f float constant. But both are equal. Hence the if condition is failed and it goes to else it prints 'C++'
Example:
#include
int main()
{
    float a=0.7;
    printf("%.10f %.10f\n",0.7f, a);
    return 0;
}
Output:
0.6999999881 0.6999999881
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum
3.Which of the following is suitable data type for the variable a in the statement given below?
(datatype) a = 23.45;
A.
float
B.
double
C.
long double
D.
long float
Answer: Option A
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum
4.Functions cannot return more than one value at a time
A.
True
B.
False
Answer: Option A
Explanation:
True, A function cannot return more than one value at a time. because after returning a value the control is given back to calling function.
Learn more problems on : Functions
Discuss about this problem : Discuss in Forum
5.What will be the output of the program?
#include
#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
int main()
{
    char *str1="India";
    char *str2="BIX";
    JOIN(str1, str2);
    return 0;
}
A.
str1=IndiaBIX str2=BIX
B.
str1=India str2=BIX
C.
str1=India str2=IndiaBIX
D.
Error: in macro substitution
Answer: Option B
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
6.Macros with arguments are allowed
A.
True
B.
False
Answer: Option A
Explanation:
True, A macro may have arguments.
Example: #define CUBE(X)(X*X*X)
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
7.If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
A.
'.'
B.
'&'
C.
'*'
D.
'->'
Answer: Option D
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum
8.Point out the error in the program
#include

int main()
{
    int *x;
    *x=100;
    return 0;
}
A.
Error: invalid assignment for x
B.
Error: suspicious pointer conversion
C.
No error
D.
None of above
Answer: Option C
Explanation:
While reading the code there is no error, but upon running the program having an unitialised variable can cause the program to crash (Null pointer assignment).
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum
9.Are the expression *ptr++ and ++*ptr are same?
A.
True
B.
False
Answer: Option B
Explanation:
*ptr++ increments the pointer and not the value, whereas the ++*ptr increments the value being pointed by ptr
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum
10.What will be the output of the program ?
#include

int main()
{
    static char mess[6][30] = {"Don't walk in front of me...", 
                               "I may not follow;", 
                               "Don't walk behind me...", 
                               "Just walk beside me...", 
                               "And be my friend." };

    printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));
    return 0;
}
A.
t, t
B.
k, k
C.
n, k
D.
m, f
Answer: Option B
Learn more problems on : Strings
Discuss about this problem : Discuss in Forum
11.Union elements can be of different sizes.
A.
True
B.
False
Answer: Option A
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum
12.Is it necessary that the size of all elements in a union should be same?
A.
Yes
B.
No
Answer: Option B
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum
13.What is the purpose of "rb" in fopen() function used below in the code?
FILE *fp;
fp = fopen("source.txt", "rb");
A.
open "source.txt" in binary mode for reading
B.
open "source.txt" in binary mode for reading and writing
C.
Create a new file "source.txt" for reading and writing
D.
None of above
Answer: Option A
Explanation:
The file source.txt will be opened in the binary mode.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
14.What will be the output of the program ?
#include

int main()
{
    printf("%%%%\n");
    return 0;
}
A.
%%%%%
B.
%%
C.
No output
D.
Error
Answer: Option B
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
15.stderr, stdin, stdout are FILE pointers
A.
Yes
B.
No
Answer: Option A
Explanation:
Yes, these will be declared like
The corresponding stdio.h variable is FILE* stdin;
The corresponding stdio.h variable is FILE* stdout;
The corresponding stdio.h variable is FILE* stderr;
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
16.What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog 1 2 3
/* myprog.c */
#include
#include

int main(int argc, char **argv)
{
    int i, j=0;
    for(i=0; i"%d\n", j);
    return 0;
}
A.
123
B.
6
C.
Error
D.
"123"
Answer: Option B
Learn more problems on : Command Line Arguments
Discuss about this problem : Discuss in Forum
17.What will be the output of the program (myprog.c) given below if it is executed from the command line?
cmd> myprog one two three
/* myprog.c */
#include
#include

int main(int argc, char **argv)
{
    int i;
    for(i=1; i<=3; i++)
        printf("%u\n", &argv[i]);
    return 0;
}
If the first value printed by the above program is 65517, what will be the rest of output?
A.
65525 65531
B.
65519 65521
C.
65517 65517
D.
65521 65525
Answer: Option B
Learn more problems on : Command Line Arguments
Discuss about this problem : Discuss in Forum
18.Bitwise | can be used to set multiple bits in number.
A.
Yes
B.
No
Answer: Option A
Learn more problems on : Bitwise Operators
Discuss about this problem : Discuss in Forum
19.What do the following declaration signify?
int (*ptr)[30];
A.
ptr is a pointer to an array of 30 integer pointers.
B.
ptr is a array of 30 integer function pointer.
C.
ptr is a array of 30 integer pointers.
D.
ptr is a array 30 pointers.
Answer: Option A
Learn more problems on : Complicated Declarations
Discuss about this problem : Discuss in Forum
20.We can allocate a 2-Dimensional array dynamically.
A.
True
B.
False
Answer: Option A
Learn more problems on : Complicated Declarations
Discuss about this problem : Discuss in Forum

No comments: