Skip to content

Instantly share code, notes, and snippets.

@Nahiduzzaman
Last active September 7, 2018 18:45
Show Gist options
  • Save Nahiduzzaman/e96f83ad9f671a985dace20072aad58d to your computer and use it in GitHub Desktop.
Save Nahiduzzaman/e96f83ad9f671a985dace20072aad58d to your computer and use it in GitHub Desktop.

Revisions

  1. Nahiduzzaman revised this gist Sep 7, 2018. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions StructAndPointer.txt
    Original file line number Diff line number Diff line change
    @@ -56,3 +56,24 @@ int main(){
    scanf("%d", &person1.age);
    printf("Age : %d", person1.age);
    }

    Fact 3

    Access structur member through pointer

    #include<stdio.h>

    typedef struct personData
    {
    int age;
    float weight;
    } person;

    int main(){
    person person1, *personPtr;
    person1.age = 12;
    person1.weight = 56.9;
    personPtr = &person1;
    printf("%d \n", personPtr->age); // you use -> only when the variable is pointer
    printf("%.1f", personPtr->weight);
    }
  2. Nahiduzzaman revised this gist Sep 7, 2018. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions StructAndPointer.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@

    https://www.programiz.com/c-programming/c-structures

    Fact 1:

    Struct Example without typedef:
    @@ -33,3 +36,23 @@ int main(){
    p1.weight = 57.9;
    printf("Age %d", p1.age);
    }


    Fact 2:

    Struct Input:

    #include <stdio.h>

    typedef struct personData
    {
    int age;
    float weight;
    } person; // "personData" is the name of struct, "person" is alternative of struct type
    // now you can use "person" to create struct object.
    int main(){
    person person1;
    printf("Enter age : ");
    scanf("%d", &person1.age);
    printf("Age : %d", person1.age);
    }
  3. Nahiduzzaman created this gist Sep 6, 2018.
    35 changes: 35 additions & 0 deletions StructAndPointer.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    Fact 1:

    Struct Example without typedef:

    struct person
    {
    int age;
    float weight;
    };

    int main(){
    struct person p1;
    p1.age = 24;
    p1.weight = 57.9;
    printf("Age %d", p1.age);
    }

    Fact 2:

    Struct Example with typedef:

    #include <stdio.h>

    typedef struct personData
    {
    int age;
    float weight;
    } person; // "personData" is the name of struct, "person" is alternative of struct type
    // now you can use "person" to create struct object.
    int main(){
    person p1;
    p1.age = 24;
    p1.weight = 57.9;
    printf("Age %d", p1.age);
    }