C coding good questions and answer


C coding good questions and answer

(1) What will be output of the following code?

#include"stdio.h"
void  main(){
char a='\\';
clrscr();
a=a-'/';
printf("%d",a);
getch();

}

Output: error

Explanation:
Character is \ has special meaning in c programming. For example:

‘\0’ represents octal character.
‘\n’ represents new line character. So we cannot use ‘\’ directly.

(2) What will be output of the following c code?

#include"stdio.h"
void  main(){
char a='\5';
clrscr();
a=a<<2;
printf("%x",a);
getch();

}

Output: 14
Explanation: ‘\5’ means octal 5.



(3) What will be output of the following program?
void main(){
clrscr();
printf("%d",__LINE__);
getch();
}
Output: 3
Explanation:
__LINE__ is global identifier in c programming language. It returns an integer which is equal to total number of line in c source code program up to __LINE__ including that line.
e.g.

void main(){  //line 1
clrscr();       //line 2
printf("%d",__LINE__);  //line 3
}

(4) What will be output of the following program?


//save this program as test.c
void main(){
clrscr();
printf("%s",__FILE__);
getch();
}

Output: test.c
Explanation:
__FILE__ is global identifier in c programming language. It returns a string containing name of current source file in which this program has been saved.

In you have any problem in C coding good questions and answer, you can ask here.
Post a Comment