C structure declarations examples



Some Structure Declarations and It’s Meaning :

struct
 {
    int length;
    char *name;
}*ptr;

Suppose we initialize these two structure members with following values –

length = 30;
*name  = "programming";

Now Consider Following Declarations one by One –
Incrementing Structure Variable in C Programming

Example 1 : Incrementing Member

++ptr->length
  1. “++” Operator is pre-increment operator.
  2. Above Statement will increase the value of “length

Example 2 : Incrementing Member

(++ptr)->length
  1. Content of the length is fetched and then ptr is incremented.

Consider above Structure and Look at the Following Table :-

    Expression       Meaning
++ptr->length Increment the value of length
(++ptr)->length Increment ptr before accessing length
(ptr++)->length Increment ptr after accessing length
*ptr->name Fetch Content of name
*ptr->name++ Incrementing ptr after Fetching the value
(*ptr->name)++ Increments whatever str points to
*ptr++->name Incrementing ptr after accessing whatever str points to