by Dinesh Thakur Category: Type And Variables

The scanf standard library function is used to read one or more values from the standard input (keyboard) and assign them to specified variables. A typical call to the scanf function takes the following form:

 
by Dinesh Thakur Category: Type And Variables

Declaring variables tells the compiler the data type the variable is assigned and no storage area is allocated during this stage. It is possible to assign values during declaration itself. In order to see how this can be done let us see an example.



 
by Dinesh Thakur Category: Type And Variables

when a variable is not initialized in main function it contains garbage value. This can be well seen from the example below

 
by Dinesh Thakur Category: Type And Variables

The input into a program and output from a program is the basic requirements of any useful program. For input from standard input device, i.e., keyboard, the function scanf () is used and for output to the standard output device, i.e., monitor, the function printf () is used. Both these functions can take any number of arguments. The first argument is the formatting string enclosed between double quotes and consists of conversion characters. For printf () function, the formatting string may also contain any text that needs to be displayed on the monitor along with the values of variables. For example, if we want to display the value of an integer variable n, we may write the code as



 
by Dinesh Thakur Category: Type And Variables

When we declare a variable name and its type, the compiler allocates a block of memory for placing its value. In fact, for the computer, this allocated block of memory is the variable and it recognizes it by its name. The sizes of memory blocks allocated for different types of data may vary on different computers depending on the hardware, the operating system, and the compiler used. The names of variables or identifiers should be carefully selected. The general guidelines are as follows:



 
by Dinesh Thakur Category: Type And Variables

Consider that we need to work with the colours in a rainbow, e. g., to paint a rainbow on the screen. We thus have to work with seven colours, namely, violet, indigo, blue, green, yellow, orange and red. These colours can be represented using integer values starting with 0. This enables us to use various program constructs such as conditions or loops to process these colours. However, programs written using such code often become difficult to understand as can be seen from the statement given below.

 
by Dinesh Thakur Category: Type And Variables

C language supports wide varieties of data types to accommodate any types of data manipulation the variety of data types available allow the programmer to select the type appropriate to the - needs for the program as well as the machine. Mainly the C language supports two types of data. type such as:



 
by Dinesh Thakur Category: Type And Variables

Type casting or type conversion refers to change of type of variables or pointers or user-defined objects from one type to another type. The need for type conversion arises in some operations involving two operands of different types, or even of same type. The example given below illustrates this concept.

 
by Dinesh Thakur Category: Type And Variables

The printf (print formatted) standard library function is used to print the values of expressions on standard output (i. e., display) in a specified format. A typical call to the printf function takes the form of a C statement as

 
by Dinesh Thakur Category: Type And Variables

The typedef feature allows us to give an alternative (possibly short and more meaningful) name to an existing data type and improve program readability. For example, instead of using the int data type to declare variables to represent marks in three subjects, we can associate a more meaningful name (say Marks)for the int data type using typedef as:



 
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content