How to structure pointer in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

struct user {
	char name[32];
	long id;
	float salary;
};
 
int main(void)
{
 	struct user u, *p;

	p = &u;
 
	strcpy(p->name, "r2d2");
    p->id = 9089387;
    p->salary = 12500;

    printf("Name: %s\nid: %ld\nsalary: %.2f", p->name, p->id, p->salary);
  
	return 0;
}





/*
run:

Name: r2d2
id: 9089387
salary: 12500.00

*/

 



answered Aug 23, 2021 by avibootz

Related questions

1 answer 96 views
96 views asked Jun 7, 2024 by avibootz
2 answers 155 views
1 answer 166 views
1 answer 134 views
1 answer 150 views
150 views asked Aug 22, 2021 by avibootz
2 answers 249 views
...