how to assign struct address to the pointer

#include<stdio.h>

struct dog
{
    char name[10];
    char breed[10];
    int age;
    char color[10];
};

int main()
{
    struct dog my_dog = {"tyke", "Bulldog", 5, "white"};
    struct dog *ptr_dog;
    ptr_dog = &my_dog;

    printf("Dog's name: %s\n", ptr_dog->name);
    printf("Dog's breed: %s\n", ptr_dog->breed);
    printf("Dog's age: %d\n", ptr_dog->age);
    printf("Dog's color: %s\n", ptr_dog->color);

    // changing the name of dog from tyke to jack
    strcpy(ptr_dog->name, "jack");

    // increasing age of dog by 1 year
    ptr_dog->age++;

    printf("Dog's new name is: %s\n", ptr_dog->name);
    printf("Dog's age is: %d\n", ptr_dog->age);

    // signal to operating system program ran fine
    return 0;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
address of struct pointer can we assign to a struct a pointer variable differentiate between pointer (*) and the address (&amp;) operator using examples how to make a struct pointer in c two notations for struct pointers c assign pointer to struct element set value to pointer member in struct llvm struct pointer C assign to a struct to a pointer pointer struct in c C what is the right way struct point to struct c use struct pointer c pointer to struct assign pointer to this in c++ passing a struct pointer as a parameter c struct poitner c struckt pointer pointer to a pointer to a struct c++ assign reference to pointer struct with pointer to other struct why can't we declare structure with a pointer in c directerally struct pointer assign and get ptr from struct pointers to structs in c pointer variable in c structure struct pointers in c struct pointer example c struct pointer in c c struct pointer get value how to assign a pointer to pointer in struct c pointers in structs c programming c struct pointer c struct pointers to variable struct pointer In the C programming language, one can declare a pointer variable that can point to a structure. is a struct a pointer c struct ptr does a struct need a pointer pointer notation and structs assigning adress to pointer struct struct point to a struct Create pointers to structure named dog. Put dog name, breed, age, color. Print the details of the dog. Mandatory condition : use only . and *. Do not use -&gt; TEST CASE 1 INPUT 2 dolly doberman 2 brown jessi abc 3 black OUTPUT dolly doberman 2 brown 0 structs and pointers in c structure pointers in c struct pointers how to create pointer of structure in c point a struct member to another pointe c how to create a pointer to a struct c write to a struct pointer in c c pointer to a struct pointer to structure c struct with pointer type int pointer in struct c pointer to struct pointer to structure in c how does a pointer store a structure how to access structure elements using pointers in c not in main struct of pointers how to declare a structer pointer in c struct pointer c struct pointers c c create pointer struct how to access pointer value inside struct c assign pointer to struct c pointer in struct c struct point struct variables from a pointer pointer to a struct how to declare a point struct and an array of point structures:
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source