#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0

    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.

    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?

    Comments on this post

    • ptr2void disagrees : Sad trombone. What are you going to do when finals come around?
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    Like
    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

    • ptr2void agrees
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    9
    Rep Power
    0
    Am I heading in the right direction?

    #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);
    }
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,392
    Rep Power
    1871
    > 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).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,174
    Rep Power
    2222
    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.
  10. #6
  11. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,113
    Rep Power
    1803
    Originally Posted by the5thace
    Am I heading in the right direction?
    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.

    This is a very simple question; you have already spent more time on this forum that it should take you to complete the exercise.

IMN logo majestic logo threadwatch logo seochat tools logo