Technology has advanced to the point where programming has become an essential part of our lives. We use software and applications for communication, entertainment, education, and work, and these are all built on programming languages.

Program to decide whether a given number is positive, negative or zero number.

Here, user will input a number and program will assign it in variable 'a' using scanf. After that, the value inside variable is checked, whether it is greater than 0 or not and if it is greater than 0 then inputted number is positive and if it is less than 0, the inputted number is negative. But if these two condition is not satisfied then the inputted number must be equal to 0. 

Output


 





Share:

When you use structure and union in C ?

Structure is a user defined data type which hold or store homogeneous data item or element in a single variable. It is a Combination of primitive and derived data type.

In C language , array is also a user defined data type but array hold or store only similar type of data, If we want to store different type of data, then we need to define separate variable for each type of data. For this problem, Structure is best suit.

 

A union is quite similar to the structures in C. It also stores different data types in the same memory location. It is also a user defined data type same like structure. It is more near to structure. Union can be defined in same manner as structures, for defining union, use union keyword where as for defining structure, use struct keyword. 

When you need to manipulate the data for all member variables then use structure. When need to manipulate only on member then use union.

All the properties of the structure are same for union, except initialization process.

In case of structure initialize all data members at a time because memory locations are different but in case of union only one member need to be initialize.

In case of union if we initialize multiple member then compiler will gives an error.


Share:

Translate

Wikipedia

Search results