943 views
1 1 vote

predict the correct options

#include <stdio.h>

int main()

{

    if (sizeof(int) > -1)

        printf("Yes");

    else

        printf("No");

    return 0;

}

1.yes

2.no

3.compiler error

3.garbage value

1 Answer

2 2 votes
really good question Thanks for post this question

sizeof return an unsigned number so -1 also converted into unsigned number which is very big in value that why it will give answer no.

if we type case first unsigned sizeof to int than it will give yes answer

#include <stdio.h>

int main()

{
    

    if ((int)sizeof(int) > -1)
    {printf("Yes");}
    else
    {printf("No");}

    return 0;

}
Position:
Show:

Related questions

0 0 votes
2 2 answers
751
751 views
Shashank Kumar Mishr asked May 18, 2017
751 views
What is the output for following code and how integer value can be assigned to a character value?#include <stdio.h>int main(){ char a = 30, b = 40, c = 10; char d =...
1 1 vote
1 answers 1 answer
3.2k
3.2k views
Shashank Kumar Mishr asked May 17, 2017
3,157 views
Assume that the size of char is 1 byte and negatives are stored in 2's complement form#include<stdio.h>int main(){ char c = 125; c = c+10; printf("%d", c); re...
3 3 votes
1 answers 1 answer
1.6k
1.6k views
Shashank Kumar Mishr asked May 17, 2017
1,640 views
Predict the output of following program. Assume that the numbers are stored in 2's complement form.#include<stdio.h>int main(){ unsigned int x = -1; int y = ~0; if...