Saturday, June 5, 2021

Constant, Variable, and keywords in C language

 

Constant, Variable, and keywords in C language

Constant, Variable, and keywords



Here we will discuss

  • C character
  • Constant
  • Variable
  • Keyword

C character

Character is a symbol that represents information like the alphabet, number, or special symbol.

Characters are as follows:

Alphabet

(A, B, C…………X, Y, Z)

(a, b, c………...…x, y, z)

Numerical Digit

(0, 1, 2, 3,…….., 8, 9)

Symbol

!@#$%^&*()_+-}{?”:’;

 

Ø Alphabet, Numerical Digit, and Symbol are combined to form constant, variable, and keyword.

Constant

Constant is an entity whose value remains the same or doesn’t change.

For example, 3 or 5 is constant as it doesn’t change.

Constant is of two types but here we will discuss only one primary type.

The primary constant is of three types:

  • Integer Constant

o  It must contain at least one digit.

o  Range of integer constant is -2147483648 to 2147483647(VS Code, by using gcc).

o  Format to write in the program is %d.

The range mainly depends upon the compiler. For Turbo C or Dev c, it is -32768 to +32768

  • Real Constant

o  It must contain at least one digit.

o  Range of a real constant is -3.4e38 or 0.000342 to 3.4e38

o  Format to write in the program is %f or %lf.

  • Character constant

o  It consists of a single alphabet and a special symbol.

o  It could with the help of inverted comma, ‘A’, ‘read’, etc.

o  Format to write in the program is %c.

Variable

Variable is an entity which can be changed.

For example, num, _dig_for_multiplication, and many more.

Rules to name variable in C

  • The first character of variable in C must be alphabet or underscore (_).
  • Variable name is the combination of alphabet, digit, and underscore. The variable name could be 247 characters but it will be safer to have 31 characters.
  • No commas, blank or other symbols are allowed.
  • Name of variables are case sensitive.

Keywords

Reserved word whose meaning are already known by the compiler are known as keywords.

There are 32 keywords which are as follow:

auto

double

int

struct

break

long

else

switch

case

return

extern

typedef

char

register

float

union

const

short

for

unsigned

continue

signed

goto

void

default

sizeof

if

volatile

do

static

enum

while

 

The basic form of a C program

The basic form of the C program shows us how we write a C program. Where it starts to execute our instruction given by the C program.

Applicable rules for all C programs are as follows:

  1. Statement of the program must be in proper order which we want to execute first.
  2. All statements must be in lowercase.
  3. All statements are finished with a semicolon (;)
  4. C program starts execution from the main function.

The first program in C

#include<stdio.h>

int main()

{

          printf(“Hello MessWithAge”);

          return 0;

}

Compilation and Execution

C program written by us is converted into machine language with the help of a computer program is known as Compiler. It helps to check the program and then execute it.

A combination of instructions is plain text and the program is written in plain text.

Comment

A comment is used to make the note of why we are writing this program. It is not executable.

Comment can be a single line or multiple lines.

Single-line Comment

//This is a statement

Multi-line Comment

/*This is a comment*/

In a single-line comment, we don’t have to close it whereas, In a multi-line comment, we have to close it.

Receive input from users

To take the input we use scanf function. Syntax of scanf function:

Scanf(“%d”,&i)

& is an ‘address of’ operator. It tells us where the supplied value has to be indicated.

Example by writing code:

Write a program to add two numbers whose data will be given by the user?

int main(){

    int a,b;

    printf("Enter the value of a and b\n");

    scanf("%d %d",&a,&b);

    printf("Addition of a and b is %d\n",a+b);

    return 0;

}

 Note \n is used to escape a line.

In the next article, we will discuss

  • Instructions
  • Operators

No comments:

Post a Comment

Please do not enter any spam link in the comment box

Best of Our Website

Popular Posts