- Signed : 'signed' specifier helps us to declare signed integer or character type variable, which can hold positive as well as negative values. By default integer and character type variables are signed.
- Unsigned : On the other hand, 'unsigned' qualifier helps us to declare variables which can hold only positive values starting from 0. If you are working with values that can’t be less than 0 like the number of cars or visitor count, you should use 'unsigned' as it gives one extra benefit. Declaring an int as unsigned can it able to hold up to double the maximum value supported by int.
- Long and Short :'Long' and 'short' specifier enables us to declare integers and double (only long specifier supported with double, short is not supported) with different lengths. Short integers are 16 bit long and have -32768 to 32767 range. Long integers have greater range -2147483647 to +2147483647.
Thursday, January 7, 2016
Other Basic Type Specifiers
Wednesday, January 6, 2016
Data Types in C Language
In a C program, data types are used to specify the type of data held by a variable or type of data returned/accepted by a function. If you remember the HelloWord Program we wrote earlier, you might have noticed that the main function returns an 'int' type response, which represents numbers.
Datatypes in C can be categorised into following sections| Basic Data Types | These are the basic built-in data types of C Programming Language. They include 'int', 'char', 'float' and 'double' |
| Enumerated Types | These are the types which can hold only a specific set of values for the variables defined using them. Name of the datatype is 'enum' |
| Void Type | Type 'void' indicates lack of data. |
| User Defined | This includes the types that can be created by the programmer using the basic types. This includes 'struct', 'union', arrays and pointers |
Basic data types
Basic data types are the built-in data types supported by C language. You can find the explanation and usage of them below
- Char : This can be used to store a single character. It can hold only one byte of data.
char var = 'a';
In the above example, variable 'var' holds a single character 'a'. - Int: This data type can be used to hold integer type of data. It may use 2/4/8 bytes depending on the architecture of the platform you're running the program. If the platform is 16 bit, int data type will use 2 bytes. If platform is of 32 bit, int data type will use 4 bytes. If platform is of 64 bit, int will use 8 bytes. 'int' variable cannot hold a floating point number.
Tuesday, January 5, 2016
Character Sets Supported by C Programs
C uses alphabets (upper case 'A' to 'Z' or lower case 'a' to 'z'), digits ('0' to '9') and some certain special characters shown in the figure below to construct basic elements of C program (constants, variables, expressions, operators etc.)
C Character Set
Identifiers and Keywords
Identifiers are the names by which we can distinguish different program elements (such as variables, constants, functions). The identifiers consist of letters (uppercase or lowercase) and digits in any possible combination as long as it follows one rule of identifiers.
The rule states that every identifier must have a letter as its first character; no digits are allowed in the first character. So, while “first” is a valid identifier, “1st” is not. Also, no identifier must contain any special character except “_” (underscore). Given below, a list of examples of valid and invalid identifiers with a reason why they are invalid.
| 1'st | Invalid (First character must be letter ) |
| first | Valid |
| total_area | Valid |
| phone-no | Invalid ( ‘-‘ not allowed ) |
| national flag | Invalid ( blank space not allowed ) |
| f1car | Valid |
There is another restriction for identifiers. Some reserved words can't be used as identifiers. These reserved words are predefined by C language and have predefined meanings and can be used for their intended purposes. They are called keywords. The list of keywords is given below
Subscribe to:
Posts (Atom)