Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5430
Number of posts: 16951

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Hey, I don't understand how to construct this basic C program! Posted by the5thace on 12 Nov 2012 at 4:14 AM
I apologize for these questions but I have fallen desperately behind my class and can't seem to understand some of these and feel to embarrassed to ask for help there! :confused:


How would I write this basic C program?
Using the sizeof(<variable or type>) function and the print function, write a program that displays the size of several variable types.

int
char
float
double
An integer array with 3 elements
a character array with 4 elements
a float array with5 elements
a double array with 6 elements

Could you please explain this to me?

this is what I got

#include <stdio.h>
int main(void){
int size_of_int = sizeof(int);
int = [3];
int size_of_float = sizeof(float);
float = [5];
int size_of_char = sizeof(char);
char = [4];
int size_of_double = sizeof(double);
double = [6];
printf = ("%d"size_of_int, size_of_float, size_of_char, size_of_double);
}
Report
Re: Hey, I don't understand how to construct this basic C program! Posted by Pelle-48 on 13 Nov 2012 at 2:28 AM
Try this code:
The answer is the number of bytes for 32bit system (16bit and 64bit will be different)

int main(void)
{
int size_of_int = sizeof(int);
int inum[3];
int size_of_float = sizeof(float);
float fnum[5];
int size_of_char = sizeof(char);
char letter[4];
int size_of_double = sizeof(double);
double dnum[6];

printf("\n%d",size_of_int);
printf("\n%d",size_of_float);
printf("\n%d",size_of_char);
printf("\n%d",size_of_double);
printf("\n%d",sizeof(inum));
printf("\n%d",sizeof(fnum));
printf("\n%d",sizeof(letter));
printf("\n%d",sizeof(dnum));
}



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.