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;
- 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.
obj.sex = 'M'; //'M' is assigned to data member sex
obj.rank = 1; // 1 is assigned to data member rank
Example:
#include <stdio.h> #include <string.h> struct student { char name[100]; int rank; }obj; int main() { strcpy(obj.name, "jp"); obj.rank = 5; printf("Name:%s\n", obj.name); printf("Rank:%d\n", obj.rank); return 0; }
Output:
jp@jp-VirtualBox:~/$ ./a.out
Name:jp
Rank:5
Name:jp
Rank:5
Dell Laptop Service center are giving repair service at the door. We should high quality Dell out of warranty Laptop Repair, removal of virus, screen removal, wireless network set up, battery removal, motherboard replacement to several other are offered at budget friendly price and it’s Negotiable. We can fix them all in time by our well experience and certified technicians. If you want to repair your laptop in front of your eyesight, than you may call us: 7217871051
ReplyDelete