Q:

What is the output of the below C code?

0

What is the output of the below C code?

#include <stdio.h>
int main(void)
{
    int var;
    for(var = -3 ; var <sizeof(int) ; var++)
    {
        printf("Hello Aticleworld\n");
    }
    return 0;
}

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Output:

Nothing will print.

Explanation: In the above C code, We are trying to compare a signed int variable “var” with size_t, which is defined as an unsigned long int (sizeof operator return size_t). Here integer promotion occurs and the compiler will convert signed int -3 to unsigned long int and resultant value would very large as compare to int size. So the for loop condition will be false and there won’t be any iteration.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Embedded C interview questions and answers (2022)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
What is the output of the below C code?... >>
<< What is the memory leak in C?...