Thread: todays how do i question

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    808

    todays how do i question

    I have the following
    Code:
    unsigned Factors[4] = { 0 }, Answer[4][4] = { { 0 } };
        const unsigned FacSize = sizeof Factors / sizeof *Factors,
                       AnsSize = sizeof Answer / sizeof **Answer;
    facsize is 4 as it should be as its a single array however, AnsSize is 16. Whilst i agree that 4 *4 = 16 and i can see why i get that it is kind of meaningless as it could describe the following
    Code:
     array[16] 
    or
    array[2][8]
    is there away of getting just the number of the second elements

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    I guess you have to do this as well.
    AnsRowSize = sizeof Answer / sizeof *Answer;

    So you can figure out the underlying dimensions.
    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.

  3. #3
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    I assume that i then divide AnsSize by AnsRowSize if thats the case can i not do this
    Code:
     AnsSize = sizeof **Answer / sizeof *Answer
    or even the other way round as i assume **Answer is smaller than *Answer

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Try some stuff, see what you get.
    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.

  5. #5
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    im still scared of it. However, i did find that with the following
    Code:
     
    int a[2][5], b[3][6], c[4][2];
    int aSize = sizeof *a / **a, bSize = *b / **b,  cSize = *c / **c;
    
    printf("%d, %d, %d\n", aSize, bSize, cSize);
    gave me an output of 5, 6, 2
    so i assume that is correct.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Todays silly questions
    By cooper1200 in forum C Programming
    Replies: 3
    Last Post: 06-06-2023, 12:16 PM
  2. Todays headache
    By cooper1200 in forum C Programming
    Replies: 10
    Last Post: 06-01-2023, 11:20 AM
  3. Getting todays date in C?
    By shwetha_siddu in forum C Programming
    Replies: 1
    Last Post: 04-08-2009, 12:05 AM
  4. The History Of Todays Problem!!
    By GodLike in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 07-07-2002, 10:39 AM
  5. Todays time and date
    By wozza in forum C Programming
    Replies: 7
    Last Post: 05-27-2002, 03:42 PM

Tags for this Thread