This blog is under construction

Sunday, 13 May 2012

Dot operator in C language

Dot operator is used to access(or assign) the values of data members in a structure.  It is represented as follows:

structure_variable.data_member = value;

struct student {
     char sex;
     int rank;
  • obj is structure variable
  • student is structure name or tag
  • sex and rank are data members
Let us try to assign values to data members in structure student using dot operator. = 'M'; //'M' is assigned to data member sex
obj.rank = 1; // 1 is assigned to data member rank


  #include <stdio.h>
  #include <string.h>
  struct student {
        char name[100];
        int rank;

  int main() {
        strcpy(, "jp");
        obj.rank = 5;
        printf("Rank:%d\n", obj.rank);
        return 0;

  jp@jp-VirtualBox:~/$ ./a.out

No comments:

Post a Comment