Skip to main content

Posts

Showing posts from June, 2016

C Interview Questions And Answers - Part 5.

What will be output of the following program? #include<stdio.h> int main() { int a = 2, b = 7, c = 10; c = a == b; printf("%d",c); return 0; } Output: 0 == is a relational operator which returns only two values. 0: If a == b is false 1: If a == b is true Since a = 2 and b = 7, so a == b is false, thus c = 0 What will be output of following program? #include<stdio.h> #include<string.h> int main() { char *ptr1 = NULL; char *ptr2 = 0; strcpy(ptr1," c"); strcpy(ptr2,"questions"); printf("\n%s %s",ptr1,ptr2); return 0; } Output: Run time error.  W e cannot assign any string constant in null pointer by strcpy function.

C Interview Questions And Answers - Part 4.

What is the output of following c program? #include<stdio.h> int main()  { int goto=5; printf("%d",goto); return 0; } Output:  Compilation error.  Because  it declared an invalid variable name. goto is a keyword in c language and variable name cannot be any keyword. What is the output of following c program? #include<stdio.h> int main() { long int 1a=5l; printf("%ld",1a); return 0; } Output: Compilation error. Because variable name cannot start with numeric value.

C Interview Questions And Answers - Part 3.

What is the meaning of NULL? Answer: NULL is a macro constant which has been defined in several header files such as stdio.h, alloc.h, mem.h, stddef.h and stdlib.h as #define NULL 0 Example 1: What is the output of following c program? #include "stdio.h" int main()`{ if(!NULL) printf("I know preprocessor"); else printf("I don't know preprocessor"); } Output: I know preprocessor Explanation: !NULL = !0 = 1, i.e. any non-zero number means true. Example 2:   What is the output of following c program? #include "stdio.h" int main() { int i; static int count; for(i=NULL;i<=5;) { count++; i+=2; } printf("%d",count); } Output: 3  What is the output if you execute following c code? #include<stdio.h> int main() { int i; for(i=0;i<5;i++) { int i=10; printf(" %d",i); i++; } return 0; } Output: 10 10 10 10 10 Explanation: The default sto