Programming Questions & Answers -
Who should Practice these C Questions?
- Anyone wishing to sharpen their skills on C programming language
- Anyone preparing for aptitude test in C (both objective type test and C coding written test)
- Anyone preparing for interviews (campus/off-campus interviews, walk-in interview and company interviews)
a) Whole source file in which it is defined
b) From the point of declaration to the end of the file in which it is defined
c) Any source file in a program
d) From the point of declaration to the end of the file being compiled
#include <stdio.h> void main() { int x = 97; int y = sizeof(x++); printf("x is %d", x); }
a) x is 97
b) x is 98
c) x is 99
d) Run time error
#include <stdio.h> void main() { char *s = "hello"; char *p = s; printf("%p\t%p", p, s); }
a) Different address is printed
b) Same address is printed
c) Run time error
d) Nothing
#include <stdio.h> struct student { char a[5]; }; void main() { struct student s[] = {"hi", "hey"}; printf("%c", s[0].a[1]); }
a) h
b) i
c) e
d) y
#include <stdio.h> void main() { static int x; if (x++ < 2) main(); }
a) Infinite calls to main
b) Run time error
c) Varies
d) main is called twice
#include <stdio.h> int main() { char *str = "hello, world"; char *str1 = "hello, world"; if (strcmp(str, str1)) printf("equal"); else printf("unequal"); }
a) equal
b) unequal
c) Compilation error
d) Depends on the compiler
a) Variables
b) Functions
c) Structures
d) None of the mentioned
#include <stdio.h> #define foo(m, n) m * n = 10 int main() { printf("in main\n"); }
a) In main
b) Compilation error as lvalue is required for the expression m*n=10
c) Preprocessor error as lvalue is required for the expression m*n=10
d) None of the mentioned
a) A structure variable pointing to itself
b) A structure variable pointing to another structure variable of same type
c) 2 different type of structure variable pointing at each other.
d) None of these
a) external linkage
b) external scope
c) global scope
d) global linkage
please explain question #6?
dude, strcmp returns zero when the strings are equal. so if statement doesn’t execute in the example
Its actually comparing the address..If that must return true then it must be like
strcmp(*str,*str1);Then this would compare the values stored in the respective variables.
it comparing a pointer address
in c , any function returns 0 as answer,if it is true
in #6,strcmp() ,on comparing both strings it gets TRUE as answer which is actually 0
on evaluating if(),condition being 0 as answer it gets false and else part executes
that’s why
answer-unequal
pls…explain me questions…4,6
4) struct student s[] has two element {“hi”, “hey”};
at s[0] = “hi” and at s[1] =”hey”
struct student has a character variable ‘a’ with size 5;
So ,if printf(“%c”, s[0].a[1]); output will be “hi”.a[1] means i the 1st location “hi”
same if printf(“%c”, s[1].a[1]); output will be e
Please explain question no 4
New program want to know
Question 2: the answer should be b) x is 98
since int y = sizeof(x++); => int y = sizeof(x); x=x+1;