c programming
zeno99 (0)

hello,
Im trying to define the variable in C programming.
Does anyone how to do it and the difference of data type while defining it?

You are viewing a single comment. View All
mwilki7 (283)

int - number values only, no letters int a = 5;
char - letters or numbers, but only 1 at a time char a = 'b';
int array - number values only, no letters int a[5] = {1,2,3,4,5};
char array - aka string, letters or numbers, one per array slot char a[5] = {'a','b','c','d','e'};
(there are other ways of defining arrays but these should do for now)

how about your OWN type?

typedef struct hotelroom
{
    int room;
    char roomname[10];
    int dailycharge;
    int floor;
} hotelroom;

Now we have a hotel room type made up of char arrays and ints

hotelroom room1;
strcpy(room1.roomname, "3B");
room1.dailycharge = 20;
room1.floor = 3;

Now we have set the data values of our special type variable