![]() Integer datatype can belong to any of 3 storage classes – short int, int and long int. Unsigned int intNum2 // this is unsigned integer variable – can contain only positive values Int intNum1 // this is a signed integer variable- can be positive or negative Unsigned integer is also of size 2bytes or 4 bytes depending on the system, but unsigned will have values from 0 to 231 for int with size 4 bytes. For unsigned datatypes, ‘unsigned’ keyword is appended before the int. Signed datatypes are normally referred as int. Integer datatype can be signed or unsigned. It is declared as: int intNum1 // variable with integer datatype That indicates, it can store values from -231 to 231 values if size of int is 4 bytes. It occupies 2 bytes (in older systems) or 4 bytes of memory. It tells the compiler that the variables declared as integer can contain only digits. This datatype declares the variable as integer. Unsigned char chOption // chOption is of character type, but unsigned char chOption // chOption is of character type It can be signed character value or unsigned character value. That means it can store values from -128 to 127. This is because, this datatype occupies only one byte of memory. But each character type of variable can hold only one character at a time. This datatype is used to declare the character variables. This datatype is basically used to declare numbers, and characters. It contains very basic types of datatypes used to define the variables and functions. ![]() } There are different types of datatypes. Printf("Marks in Subject 2 is: %f\n", marks2) Printf("Marks in Subject 1 is: %f\n", marks1) // display the variable value #include Įxtern float marks1, marks2 // declare float variablesįloat marks1, marks2 //define the same float variables, since it is actually being used here The keyword ‘extern’ is used to declare the variable in this case and it allows defining those variables anywhere in the program – that means in any of the function in the program. We can even declare, define and initialize the variables at different steps too. If we give the initial value to the variable while declaring them, then it both defines and initializes the variable. When we declare a variable like above inside any function, it defines the variable. Int intNum1 // variable with integer datatype, defines the variableįloat flNum=3.14 // Variable with real number, defines and initializes the variableĬhar chOption // chOption is of character type Enumerated Datatypes A variable is declared using its datatype as below : datatype variable_name.Non-primitive/ Derived/ Structured Datatype.Primitive / Basic/ Fundamental Datatype.There are different types of datatypes.A variable is declared using its datatype as below :.These datatypes are the reserved keywords in C like int, float, double, char etc. Variables are declared with their respective datatypes at the beginning of the program, before using them in the program/function. Datatypes defines the variables and functions along with the range of data stored, type of data stored and indicates how much bytes of memory are occupied. Like variables, if we predefine the type of data that it returns, it makes the program more logical.Īll these are done by using the datatypes in C. This also needs memory location which is named as function name. Even though functions are meant for performing certain task, it will have result values which need to be returned to the calling functions. Similarly, C language revolves around functions. That means, it gives the systematic usage of the variables in the program and avoids any confusions and mishandling of data. If we define type of data that each variable can store, it adds values for a systematic programming using C. But we cannot store all types of data in all the variables. ![]() ![]() These variables can be used to get the values from the user, can be used in various calculations, or displaying some result or messages. Hence we use variables – a named memory location to store these values. Even though memory location will have its own address, it is easy to identify them by name than their address. Such values need to be stored in the memory location. When we code in a program, we need to store certain values for latter use in the program. ![]()
0 Comments
Leave a Reply. |