Thread: How can i find the size of a struct?

  1. #1
    Registered User
    Join Date
    Dec 2018
    Posts
    4

    How can i find the size of a struct?

    i have a struct that include 2 points:
    A and B
    i need to make a function that gets a pointer of an array and return the biggest sum of A and B.
    The thing is that i don't know the size of the array.
    I tryed to write this:

    int SizeOfArr = sizeof(Arr)/sizeof(Num);

    But the size of Arr does not fit well because it is a pointer and not an array.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,415
    So you have?
    Code:
    struct Point {
        int x,y;
    };
    struct Points {
        Point A,B;
    };
    
    int sumOfPoints(Points *arrayOfPointsWithNoSize) {
        // do stuff
    }
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Find size of int array
    By JonathanS in forum C Programming
    Replies: 2
    Last Post: 01-18-2012, 04:12 PM
  2. Struct field containing size of struct
    By DL1 in forum C Programming
    Replies: 7
    Last Post: 10-10-2011, 10:37 PM
  3. to find the heap size
    By starvijay in forum C Programming
    Replies: 4
    Last Post: 04-17-2006, 02:28 PM
  4. Given tha path, find an exe(given the size) into it
    By BianConiglio in forum C Programming
    Replies: 1
    Last Post: 04-01-2004, 06:50 PM
  5. How to find file size?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 08-30-2001, 02:34 PM

Tags for this Thread