-
-
Loops in C programming.
main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j -
Recursion C program.
main() { static int var = 5; printf("%d ",var--); if(var) main(); }
Ans:5 4 3 2 1 Explanation:When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively. -
Different ways of expressing the same idea.
main(){ char s[ ]="man"; int i; for(i=0;s[ i ];i++) printf("n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);}
Ans:mmmm
aaaa
nnnn
Explanation:s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting... -
-
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
">Ix) main(){ int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }
threeExplanation :The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.
-
}
">X) main(){ printf("%x",-1
fff0Explanation :-1 is internally represented as all 1's. When left shifted four times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value
-
-
Is it acceptable to declare/define a variable in a C header?
A global variable that must be accessed from more than one file can and should be declared in a header file. In addition, such a variable must be defined in one source file. Variables should not be defined in header files, because the header file can be included in multiple source files, which would cause multiple definitions of the variable. The ANSI C standard will allow multiple external definitions,...
-
-
}
">Main(){ int i = 100; clrscr(); printf("%d", sizeof(sizeof(i)));}
A) none of the aboveB) 4C) 100D) 2
-
What would be the output of the following program? main() { int y=128; const int x=y; printf("%d",x); }
A) 128B) Garbage valueC) ErrorD) 0
-
Point out the error in the following program main() { int a=10; void f(); a=f(); printf("n%d",a); } void f() { printf("nHi"); }
The program is trying to collect the value of a "void" function into an integer variable.
-
-
-
-
-
-
-
C Interview Questions
Ans