Thread: Why need a dot between structure variable and structure member ?

  1. #1
    Registered User
    Join Date
    Nov 2019
    Posts
    32

    Why need a dot between structure variable and structure member ?

    Why need a dot between structure variable and structure member ?

    Code:
    #include<stdio.h>
    
    struct Point { 
       int x, y; 
    };  
      
    int main() { 
    
    
        struct Point p1;
    	
        p1.x = 13;
        p1.y = 14;	  
    }
    as can see p1.x and p1.y What does it means

  2. #2
    Registered User
    Join Date
    Feb 2019
    Posts
    649
    Quote Originally Posted by skyr6546 View Post
    Why need a dot between structure variable and structure member ?
    C language expressions

  3. #3
    Registered User
    Join Date
    Nov 2019
    Posts
    32
    Quote Originally Posted by flp1969 View Post
    it say dot will use to access structure member but there is no information why the dot will only use.

    Does structure variable point structure member to assign value ?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,567
    p1.x means the member named x of the struct (or union) object named p1.

    If there was no dot, then it would be impossible to differentiate between this and a variable named p1x.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Copy a whole structure in one of its member in C
    By mehtame026 in forum C Programming
    Replies: 6
    Last Post: 11-15-2016, 02:46 AM
  2. Replies: 10
    Last Post: 03-18-2014, 10:43 AM
  3. Not recognizing structure member
    By Jon Hanson in forum C Programming
    Replies: 1
    Last Post: 08-31-2011, 09:14 PM
  4. member of a structure that is a stucture member
    By MK27 in forum C Programming
    Replies: 2
    Last Post: 11-29-2008, 10:33 AM
  5. structure member initialization
    By ivandn in forum C Programming
    Replies: 4
    Last Post: 10-27-2001, 01:27 PM

Tags for this Thread