Point (.) in struct

+2 Sergiu Man · August 5, 2014
Hey, i'm learning a code about stack and heap memory. but i have a struct when he use (.) and i don't understand what does that (.)

struct Address {
int id;
int set;
char name[MAX_DATA];
char email[MAX_DATA];
};
void Database_create(struct Connection *conn)
{
int i = 0;

for(i = 0; i < MAX_ROWS; i++) {
// make a prototype to initialize it
struct Address addr = {.id = i, .set = 0};
// then just assign it
conn->db->rows = addr;

Post a Reply

Replies

Oldest  Newest  Rating
+2 Bucky Roberts · August 19, 2014
The dot lets you access the variables (called "members") inside your structure. For example...

BuckysInfo.h

struct user{
    int userID;
};


main.c

#include <stdio.h>
#include <stdlib.h>
#include "BuckysInfo.h"

int main()
{
   struct user bucky;
   //use the dot after the structure variable to access the members
   bucky.userID = 290;
   printf("User 1 id is %d\n", bucky.userID);  //will print "User 1 id is 290"
   return 0;
}

  • 1

C

107,210 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator