C Interview Questions And Answers

adplus-dvertising
C FAQS
Previous Home Next

C,C++ Questions with answers, C++ Questions Interview with answers

C,C++ Questions

Questions 6.
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}
Ans: 6

Questions 7.
void main()
{
unsigned i=1; /* unsigned char k= -1 => k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i<j)
printf("less");
else
if(i>j)
printf("greater");
else
if(i==j)
printf("equal");
}
Ans: less

Questions 8.
void main()
{
float j;
j=1000*1000;
printf("%f",j);
}

1. 1000000
2. Overflow
3. Error
4. None

Ans: 4

Questions 9. 

How do you declare an array of N pointers to functions returning
     pointers to functions returning pointers to characters?

Ans: The first part of this question can be answered in at least
        three ways:

    1. char *(*(*a[N])())();

    2. Build the declaration up incrementally, using typedefs:

        typedef char *pc;    /* pointer to char */
        typedef pc fpc();    /* function returning pointer to char */
        typedef fpc *pfpc;    /* pointer to above */
        typedef pfpc fpfpc();    /* function returning... */
        typedef fpfpc *pfpfpc;    /* pointer to... */
        pfpfpc a[N];         /* array of... */

    3. Use the cdecl program, which turns English into C and vice
    versa:

        cdecl> declare a as array of pointer to function returning
            pointer to function returning pointer to char
        char *(*(*a[])())()

    cdecl can also explain complicated declarations, help with
    casts, and indicate which set of parentheses the arguments
    go in (for complicated function definitions, like the one
    above).
    Any good book on C should explain how to read these complicated
    C declarations "inside out" to understand them ("declaration
    mimics use").
    The pointer-to-function declarations in the examples above have
    not included parameter type information. When the parameters
    have complicated types, declarations can *really* get messy.
    (Modern versions of cdecl can help here, too.)

Questions 10.
A structure pointer is defined of the type time . With 3 fields min,sec hours having pointers to intergers.
    Write the way to initialize the 2nd element to 10.

Previous Home Next