Digital Learning

Wednesday, December 25, 2019

Constants and Keywords in C Language:

Kinds of C Constants: 

C constants can be isolated into two significant classes: 

1. Primary Constants
2. Secondary Constants 

These constants are additionally sorted as follows: 

1. Primary Constants

i. Integer constants 
ii. Real constants 
iii. Character Constant 

2. Secondary Constants 

i. Array 
ii. Pointer 
iii. Structure 
iv. Union 
v. Enum. and so on. 

Rules for Constructing Integer Constants: 
a. A Integer steady should have in any event one digit. 
b. It must not have a decimal point 
c. It tends to be either positive or negative 
d. On the off chance that no sign goes before a number Constant, it is thought to be sure. 
e. No commas or spaces are permitted withing a Integer steady. 
f. The suitable range for number constants is - 32768 to 32767. 

Rules for Constructing Real Constants: 
Real constants are regularly called Floating point constants. The Real constants could be written in two structures Fractional structure and Exponential structure. 

Keeping rules must be watched while developing Real constants communicated in fragmentary structure: 

a. A Real steady should have at any rate one digit. 
b. It must have a decimal point. 
c. It could be either positive or negative. 
d. Default sign is sure. 
e. No commas or spaces are permitted inside a Real Constant. 

Rules for Constructing Character Constants: 
a. A character Constant is a solitary letter set, a solitary digit or a solitary exceptional image encased inside single upset commas. Both the rearranged commas should highlight the left, For instance, 'A' will be a substantial character steady though 'An' isn't. 

b. The greatest length of a character steady can be 1 character. 
Model: 

'A' 
'I' 
'5' 
'=' 
C Keywords: 

Keywords are the words whose importance has just been disclosed to the C compiler. 

The Keywords can't be utilized as factor names supposing that we do as such, we are attempting to allot another significance to the catch phrase, which isn't permitted by the PC. Some C compilers permit you to build variable names that precisely look like the watchwords. Be that as it may, it would be more secure not to stir up the variable names and the keywords. The watchwords are likewise called 'Held words'. 

There are just 32 Keywords accessible in C. 

auto            double               int                  struct

break          else                    long               switch

case            enum                 register           typedef

char            extern                return             union

const          float                   short               unsigned

continue     for                     signed             void

default        goto                  sizeof              volatile

do               if                       static               while

Program: C program for addition of two numbers. 

#include<stdio.h> 
#include<conio.h> 
void main() 

int a=25, b=15, c; 
c=a+b; 
printf("%d", c); 
getch(); 

Output: 40.

Secondary Constant:

Array:
C language provides a ability that allow the user to design a group of similar data types called array. An array can hold many elements of similar data types. These elements may be ints, floats, chars etc. An array of many characters is also called a string. There may be an array of pointers like array of ints. Pointer variable contains address, array of pointers is a collection of addresses.

Example:
#include<stdio.h>
void main()
{
int marks[40]; /* array declaration*/
.
.
.
}
Structures:
A structure is a user defined data type. A structure is a combination of many different already defined data types.
A structure is a collection of variables. It is also known as group of related data.

Syntax:
struct structure_name
{
member1;
member2;

};

No comments:

Post a Comment