November 12th, 2012, 06:54 AM
Could you please help me construct some of these basic C programs?
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.
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?
Comments on this post
November 12th, 2012, 07:26 AM
printf("%d\n", sizeof(char) );
The rest you'll have to figure out for yourself.
> but I have fallen desperately behind my class and can't seem to understand some of these
Perhaps you should post the one's you are specifically having trouble with, along with what you have achieved yourself.
FWIW, if you're that far behind, you really need to talk to your tutor, to try and work out some kind of catch-up plan.
Your homework is beginning of the book basic stuff, there are much harder things coming. Unless you can put the effort in to catch up quickly, you're just going to end up failing.
Comments on this post
November 12th, 2012, 07:36 AM
Am I heading in the right direction?
int size_of_int = sizeof(int);
int = ;
int size_of_float = sizeof(float);
float = ;
int size_of_char = sizeof(char);
char = ;
int size_of_double = sizeof(double);
double = ;
printf = ("%d"size_of_int, size_of_float, size_of_char, size_of_double);
November 12th, 2012, 08:41 AM
> Am I heading in the right direction?
Paste it into your compiler, and find the answer in a few seconds (rather than waiting for what could be hours).
November 12th, 2012, 03:47 PM
And be sure to set your compiler to display warnings, so that it can scold you for not returning an int as you had promised.
November 13th, 2012, 05:09 AM
No. The right direction would be a series of statements similar to that Salem posted - he's done the first one for you! You have severely overcomplicated the solution.
Originally Posted by the5thace
This is a very simple question; you have already spent more time on this forum that it should take you to complete the exercise.