C coding questions with answer

C coding questions with answers and explanation

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

#include<stdio.h>
int main(){
long int a;
(float)a=6.5;
printf("%f",a);
return 0;
}

Output: error, L value required
Explanation:
After applying any operator in variable name it always give a value.
(Type): urinary type casting operator is not exception for this. It is similar to write
3456 = 5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

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

#include<stdio.h>
int main(){
long int a,b=10;
++a=b++;
printf("%d  %d",a,b);
return 0;
}

Output: error, L value required
Explanation:
After applying any operator in variable name it always give a value.
(Type): urinary type casting operator is not exception for this. It is similar to write
3456=5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

No comments: