Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

c programming

+11 votes
asked Oct 9, 2022 by mijeong (220 points)
#include<stdio.h>
int main()
{
    char ch=9;
    int inum=1052;
    double dnum=3.1415;
    
    printf("ch의 크기: %d\n", sizeof(ch));
    printf("inum의 크기: %d\n", sizeof(inum));
    printf("dnum의 크기: %d\n", sizeof(dnum));
    
    printf("char의 크기: %d \n", sizeof(char));
    printf("int의 크기: %d \n", sizeof(int));
    printf("long의 크기: %d \n", sizeof(long));
    printf("long long 의 크기: %d \n", sizeof(long long));
    printf("float의 크기: %d \n", sizeof(float));
    printf("double의 크기: %d \n", sizeof(double);
    return 0;
}

code doesn't work. what's wrong ?

2 Answers

+2 votes
answered Oct 10, 2022 by Peter Minarik (86,200 points)

You're missing a closing parenthesis from the double line (last printf).

Also, it's not an error, but a warning: the correct type to print for the return type of sizeof() is a long unsigned int (lu), not a signed int (d).

Last, but not least, sizeof() works on types as well, not just on variables.

#include<stdio.h>

int main()
{
    char ch = 9;
    int inum = 1052;
    double dnum = 3.1415;
    
    printf("ch의 크기: %lu\n", sizeof(ch));
    printf("inum의 크기: %lu\n", sizeof(inum));
    printf("dnum의 크기: %lu\n", sizeof(dnum));
    printf("char의 크기: %lu\n", sizeof(char));
    printf("int의 크기: %lu\n", sizeof(int));
    printf("long의 크기: %lu\n", sizeof(long));
    printf("long long 의 크기: %lu\n", sizeof(long long));
    printf("float의 크기: %lu\n", sizeof(float));
    printf("double의 크기: %lu\n", sizeof(double));
    
    printf("printf works on types too! sizeof(char) = %lu\n", sizeof(char));
    return 0;
}
0 votes
answered Oct 16, 2022 by DDForbes (140 points)
In addition to the previous answer, I noticed you have the integer "9" stored in a char variable.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...