C Programming

C25: Examples on Pointer Usage
This program introduces a structure which contains pointers as some of its fields.

Determine the output of the following program.


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

struct  sample {
	char *name;
	int *id;
	float price;
};

static char product[]="Red Plum Jam";

main()
{
	int code = 312, number;
	char name[] = "Baked beans";
	struct sample item;

	item.name = product;
	item.id = &code;
	item.price = 2.75;
	item.name = name;
	number = *item.id;
	printf("Name = %s\n", item.name );
	printf("ID = %d\n", *item.id);
	printf("Price = %.2f\n", item.price );
}

Answer


ęCopyright B Brown. 1984-1999. All rights reserved.