Sei sulla pagina 1di 8

C interview questions and answers

1.
What will print out? main() { char *p1=name; char *p2; p2=(char*)malloc(20); memset (p2, 0, 20); while(*p2++ = *p1++); printf(%sn,p2); } Answer:empty string. 2. What will be printed as the result of the operation below:

main() { int x=20,y=35; x=y++ + x++; y= ++y + ++x; printf(%d%dn,x,y); }


Answer : 5794 3. What will be printed as the result of the operation below:

main() { int x=5; printf(%d,%d,%dn,x,x< <2,x>>2); }


Answer: 5,20,1

4.

What will be printed as the result of the operation below:

#define swap(a,b) a=a+b;b=a-b;a=a-b; void main() { int x=5, y=10; swap (x,y); printf(%d %dn,x,y); swap2(x,y); printf(%d %dn,x,y); } int swap2(int a, int b) { int temp; temp=a; b=a; a=temp; return 0; }
Answer: 10, 5 10, 5 5. What will be printed as the result of the operation below:

main() { char *ptr = Cisco Systems; *ptr++; printf(%sn,ptr); ptr++; printf(%sn,ptr); }


Answer:Cisco Systems isco systems

6.

What will be printed as the result of the operation below:

main() { char s1[]=Cisco; char s2[]= systems; printf(%s,s1); }


Answer: Cisco 7. What will be printed as the result of the operation below:

main() { char *p1; char *p2; p1=(char *)malloc(25); p2=(char *)malloc(25); strcpy(p1,Cisco); strcpy(p2,systems); strcat(p1,p2); printf(%s,p1); }
Answer: Ciscosystems 8. The following variable is available in file1.c, who can access it?:
9. static int average;

Answer: all the functions in the file1.c can access the variable. 10. 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. 11. What will be printed as the result of the operation below:

int x; int modifyvalue() { return(x+=10); } int changevalue(int x) { return(x+=1); } void main() { int x=10; x++; changevalue(x); x++; modifyvalue(); printf("First output:%dn",x); x++; changevalue(x); printf("Second output:%dn",x); modifyvalue(); printf("Third output:%dn",x); }
Answer: 12 , 13 , 13 12. What will be printed as the result of the operation below:

main() { int x=10, y=15; x = x++; y = ++y; printf(%d %dn,x,y); }


Answer: 11, 16

13. 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.

1. What is C language ? 2. What does static variable mean? 3. What are the different storage classes in C ? 4. What is hashing ? 5. Can static variables be declared in a header file ? 6. Can a variable be both constant and volatile ? 7. Can include files be nested? 8. What is a null pointer ? 9. What is the output of printf("%d") ? 10. What is the difference between calloc() and malloc() ? 11. What is the difference between printf() and sprintf() ? 12. How to reduce a final size of executable ? 13. Can you tell me how to check whether a linked list is circular ? 14. Advantages of a macro over a function ? 15. What is the difference between strings and character arrays ? 16. Write down the equivalent pointer expression for referring the same
element a[i][j][k][l] ?

17. Which bit wise operator is suitable for checking whether a particular bit is
on or off ?

18. Which bit wise operator is suitable for turning off a particular bit in a
number ?

19. Which bit wise operator is suitable for putting on a particular bit in a
number ?

20. Does there exist any other function which can be used to convert an
integer or a float to a string ?

21. Why does malloc(0) return valid memory address ? What's the use ? 22. Difference between const char* p and char const* p 23. What is the result of using Option Explicit ? 24. What is the benefit of using an enum rather than a #define constant ? 25. What is the quickest sorting method to use ? 26. When should the volatile modifier be used ? 27. When should the register modifier be used? Does it really help ? 28. How can you determine the size of an allocated portion of memory ? 29. What is page thrashing ? 30. When does the compiler not implicitly generate the address of the first
element of an array ?

31. What is the benefit of using #define to declare a constant ? 32. How can I search for data in a linked list ? 33. Why should we assign NULL to the elements (pointer) after freeing them ? 34. What is a null pointer assignment error ? What are bus errors, memory
faults, and core dumps ?

35. When should a type cast be used ? 36. What is the difference between a string copy (strcpy) and a memory copy
(memcpy)? When should each be used?

37. How can I convert a string to a number ? 38. How can I convert a number to a string ? 39. Is it possible to execute code even after the program exits the main()
function?

40. What is the stack ? 41. How do you print an address ? 42. Can a file other than a .h file be included with #include ? 43. What is Preprocessor ? 44. How can you restore a redirected standard stream ? 45. What is the purpose of realloc( ) ? 46. What is the heap ? 47. How do you use a pointer to a function ? 48. What is the purpose of main( ) function ? 49. Why n++ executes faster than n+1 ? 50. What will the preprocessor do for a program ? 51. What is the benefit of using const for declaring constants ? 52. What is the easiest sorting method to use ? 53. Is it better to use a macro or a function ? 54. What are the standard predefined macros ? 55. why we use pointer in c 56. What is pre-emptive data structure and explain it with example?

57. Is double link list a linear data structure? If Yes, Why?If No, Why? 58. write a program in reverse the string without using pointer,array,global variable declaration,lib fun only using a function? 59. find largest of 3 no 60. #include<stdio.h> int main() { int i=0,j=1,k=2,m,n=0; m=i++&&j++&&k++||n+ +; printf("%d,%d,%d,%d,%d",i,j,k,m,n); } 61. Find the output? void main() {float a=2.0; printf("\nSize of a ::%d",sizeof(a)); printf("\nSize of 2.0 ::%d",sizeof(2.0));} 62. how to find anagram without using string functions using only loops in c programming 63. How to removing white spces in c programming only bu using loops 64. 4) Write a program that takes a 5 digit number and calculates 2 power that number and prints it. i have done maximum par but i m findind problem in the commented area. please help... 65. what is default constructor? 66. biggest of two no's with out using if condition statement 67. what are the 10 different models of writing an addition program in C language 68. find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2

Potrebbero piacerti anche