void main()
{
int const *p=5;
printf("%d", ++(*p));
} p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
Learn competitive and Technical Aptitude C programming mcq questions and answers on C Miscellaneous questions with easy and logical explanations.
void main()
{
int const *p=5;
printf("%d", ++(*p));
} p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
void main()
{
char s[]="man";
int i;
for(i=0; s[i]; i++)
printf("%c%c%c%c ", s[i], *(s+i), *(i+s), i[s]);
}
void main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I hate Examveda");
else
printf("I love Examveda");
} For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb: Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) .
void main()
{
static int var = 5;
printf("%d ", var--);
if(var)
main();
} 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.
void main()
{
char *p;
printf("%d %d", sizeof(*p), sizeof(p));
} The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.
void main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
} \n - newline - printf("\nab"); - Prints ab
\b - backspace - printf("\bsi"); - firstly '\b' removes 'b' from 'ab ' and then prints 'si'. So after execution of printf
void main()
{
int i=10;
i=!i>14;
printf("i=%d", i);
} In the expression !i>14 , NOT (!) operator has more precedence than ">" symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).
void main()
{
int c = - -2;
printf("c=%d", c);
}
void main()
{
int c = - -2;
printf("c=%d", c);
}
#define int char
void main()
{
int i = 65;
printf("sizeof(i)=%d", sizeof(i));
} Since the #define replaces the string int by the macro char.
void main()
{
int i=3;
switch(i)
{
default: printf("zero");
case 1: printf("one"); break;
case 2: printf("two"); break;
case 3: printf("three"); break;
}
} The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.