c interview q

Upload: santosh-kadam

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 C Interview Q

    1/3

    1) What is the difference between const char* p and char const* p ?

    2) How to make sure, the header file is included only once?

    3) Can a static be declared in a header file?

    4) What is an advantage of a macro over a function?

    5) #define PRINT(EXPR) printf( #EXPR =%d\n, EXPR)PRINT (5+6*7); == printf(5+6*7=%d, 5+6*7 );

    6)What are the different storage classes in C ?C has three types of storage: automatic, static and allocated.

    7)Can you tell me how to check whether a linked list is circular?while (pointer1) {pointer1 = pointer1->next;pointer2 = pointer2->next;if (pointer2) pointer2=pointer2->next;if (pointer1 == pointer2) {print ("circular");}}

    8) What is the difference between enum and #define?

    9)Write down the equivalent pointer expression for referring the same element a[i][j][k][l] ?a[i] == *(a+i)a[i][j] == *(*(a+i)+j)a[i][j][k] == *(*(*(a+i)+j)+k)a[i][j][k][l] == *(*(*(*(a+i)+j)+k)+l)

    10) How to swape two numbers without using a tmp?

    #includeint main(){

    int a=5,b=10;//process onea=b+a;b=a-b;a=a-b;printf("a= %d b= %d",a,b);

    11) You can modify constant variable with the help of pointers. For example:

    #includeint main(){

    int i=10;int *ptr=&i;

    *ptr=(int *)20;printf("%d",i);return 0;

    }

    12) Write a c program to find size of structure without using sizeof operator?struct ABC{

    int a;float b;char c;

  • 7/28/2019 C Interview Q

    2/3

    };int main(){

    struct ABC *ptr=(struct ABC *)0;ptr++;printf("Size of structure is: %d",*ptr);return 0;

    }

    13) What is size of void pointer?2 Bytes

    14) How do you override a defined macro?

    15) Write the equivalent expression for x%8?x&7 , x-(8 * (x/8))

    16) What are the different storage classes in C ?

    17) What is the differece between #define and constant in C?A const identifier allows a variable to be constant throughout the file in whichit's declared....Whereas a #define is a macro which replaces the macro-name with a user-defined text statement.....

    Also,a macro can be deleted,if we wish,using #undef whereas a const variable once defined can't be done so....

    A constant identifier declared the constant throughout the file in which it's declared.In #define we can use the value globally any where of the prog.

    18) Write a C program to print that a number is odd or even?

    19) How many levels deep can include files be nested?

    Even though there is no limit to the number of levels of nested include files you can have,

    your compiler might run out of stack space while trying to include an inordinately high number of files.This number varies according to your hardware configuration and possibly your compiler.

    20) which one will execute faster if(flag==0) or if (0==flag) and why?

    21) Write a macro to swap a number#define swap(a,b) a=a+b;b=a-b;a=a-b;

    22) main(){

    int c=- -2;

    printf("c=%d",c);}

    Ans: c=2 as (- -) = +.

    23) main(){int i=10;i=!i>14;Printf ("i=%d",i);

  • 7/28/2019 C Interview Q

    3/3

    }

    And: i=0

    24)main(){

    printf("%x",-1