Knowee
Questions
Features
Study Tools

Write a C program that prints the size of various types on the computer it is compiled and run on.You should produce the exact same output as in the exampleWarnings are allowedYour program should return 0You might have to install the package libc6-dev-i386 on your Linux to test the -m32 gcc option

Question

Write a C program that prints the size of various types on the computer it is compiled and run on.You should produce the exact same output as in the exampleWarnings are allowedYour program should return 0You might have to install the package libc6-dev-i386 on your Linux to test the -m32 gcc option

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple C program that prints the size of various types on the computer it is compiled and run on:

#include <stdio.h>

int main() {
    printf("Size of char: %lu byte\n", sizeof(char));
    printf("Size of int: %lu bytes\n", sizeof(int));
    printf("Size of float: %lu bytes\n", sizeof(float));
    printf("Size of double: %lu bytes\n", sizeof(double));
    printf("Size of short int: %lu bytes\n", sizeof(short int));
    printf("Size of long int: %lu bytes\n", sizeof(long int));
    return 0;
}

This program uses the sizeof operator to find the size of various data types. The sizeof operator returns the size of the data type in bytes. The %lu format specifier is used to print the size as an unsigned long integer.

To compile and run this program, you can use the following commands in a terminal:

gcc -o size size.c
./size

Replace size.c with the name of your C file. If you want to compile for a 32-bit architecture, you can use the -m32 option:

gcc -m32 -o size size.c
./size

If you get an error about missing libraries, you might need to install the libc6-dev-i386 package. You can do this with the following command:

sudo apt-get install libc6-dev-i386

This problem has been solved

Similar Questions

Write a C program that prints exactly and that piece of art is useful" - Dora Korpar, 2015-10-19, followed by a new line, to the standard error.You are not allowed to use any functions listed in the NAME section of the man (3) printf or man (3) putsYour program should return 1Your program should compile without any warnings when using the -Wall gcc option

What will be the output of this program? (on a standard 64 bits, Linux machine)#include <stdio.h>#include <stdlib.h>#define int charint main(void){ int i; i = 5; printf ("sizeof(i) = %lu", sizeof(i)); return (EXIT_SUCCESS);}It does not compileSegmentation Faultsizeof(i) = 4sizeof(i) = 1sizeof(i) = 8sizeof(i) = 5

Select the correct answerThe size_t data type is commonly used as the return type for which library function in C?Optionsscanf()printf()malloc()getchar()

Size of an integer is 32 bit. What is the output of following program?#include<stdio.h>struct student{    int a;    int b;};int main(){    printf("%d", sizeof(struct student));    return 0;}a.4b.8c.Compile Errord.Runtime Error

What is the sizeof(char) in a 32-bit C compiler?*1 point1 bit2 bits1 Byte2 Bytes

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.