Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C Programming Language: Understanding Constants, Variables, and Keywords, Thesis of Computer Science

An introduction to the C programming language, focusing on constants, variables, and keywords. It covers the rules for constructing different types of constants and variables, as well as the meaning and usage of keywords. C is a fundamental programming language that forms the basis for many modern programming languages, making it an essential topic for students and developers.

What you will learn

  • What is the history of the C programming language?
  • What are the rules for constructing real constants in C?
  • How do you declare and initialize variables in C?
  • What are the different types of control instructions in C?
  • What is the difference between constants and variables in C?

Typology: Thesis

2020/2021

Uploaded on 01/21/2021

Suraba
Suraba 🇮🇳

4 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
C language
What is C C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It
was designed and written by a man named Dennis Ritchie. In the late seventies C began to replace
the more familiar languages of that time like PL/I, ALGOL, etc. No one pushed C. It wasn’t made
the ‘official’ Bell Labs language. Thus, without any advertisement C’s reputation spread and its pool
of users grew. Ritchie seems to have been rather surprised that so many programmers preferred C
to older languages like FORTRAN or PL/I, or the newer ones like Pascal and APL. But, that's what
happened.
C++, C# or Java make use of a principle called Object Oriented Programming (OOP) to organize
the program. This organizing principle has lots of advantages to offer. But even while using this
organizing principle you would still need a good hold over the language elements of C and the basic
programming skills.
Though many C++ and Java based programming tools and frameworks have evolved over the
years the importance of C is still unchallenged because knowingly or unknowingly while using these
frameworks and tools you would be still required to use the core C language elements—another good
reason why one should learn C before C++, C# or Java.
The c characters set
Constants, Variables and Keywords :-
The alphabets, numbers and special symbols when properly combined form constants, variables and
keywords. Let us see what are ‘constants’ and ‘variables’ in C. A constant is an entity that doesn’t
change whereas a variable is an entity that may change.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download C Programming Language: Understanding Constants, Variables, and Keywords and more Thesis Computer Science in PDF only on Docsity!

C language

What is C C is a programming language developed at AT & T’s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. In the late seventies C began to replace the more familiar languages of that time like PL/I, ALGOL, etc. No one pushed C. It wasn’t made the ‘official’ Bell Labs language. Thus, without any advertisement C’s reputation spread and its pool of users grew. Ritchie seems to have been rather surprised that so many programmers preferred C to older languages like FORTRAN or PL/I, or the newer ones like Pascal and APL. But, that's what happened.

C++, C# or Java make use of a principle called Object Oriented Programming (OOP) to organize the program. This organizing principle has lots of advantages to offer. But even while using this organizing principle you would still need a good hold over the language elements of C and the basic programming skills.

Though many C++ and Java based programming tools and frameworks have evolved over the years the importance of C is still unchallenged because knowingly or unknowingly while using these frameworks and tools you would be still required to use the core C language elements—another good reason why one should learn C before C++, C# or Java.

The c characters set

Constants, Variables and Keywords :-

The alphabets, numbers and special symbols when properly combined form constants, variables and keywords. Let us see what are ‘constants’ and ‘variables’ in C. A constant is an entity that doesn’t change whereas a variable is an entity that may change.

Classification of constant in c

We have to follow some Rules for construncting different types of C constant.

Here we discusse about primary constant only.

(a) Rules for Constructing Integer Constants:-

  1. An integer constant must have at least one digit.
  2. It must not have a decimal point.
  3. It can be either positive or negative.
  4. If no sign precedes an integer constant it is assumed to be positive.
  5. No commas or blanks are allowed within an integer constant.
  6. The allowable range for integer constants is -32768 to 32767.

Rules for Constructing Real Constants Real:-

constants are often called Floating Point constants. The real constants could be written in two forms—Fractional form and Exponential form.

Following rules must be observed while constructing real constants expressed in fractional form:

  1. A real constant must have at least one digit.

2.It must have a decimal point.

  1. It could be either positive or negative. Default sign is positive. No commas or blanks are allowed within a real constant.

Ex.: si_int m_hra

C Keywords:-

Keywords are the words whose meaning has already been explained to the C compiler (or in a broad sense to the computer). The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. Some C compilers allow you to construct variable names that exactly resemble the keywords. However, it would be safer not to mix up the variable names and the keywords. The keywords are also called ‘Reserved words’.

We use these keywords in our c programs later.

Before we begin with our first C program do remember the following rules that are applicable to all C programs:

  1. Each instruction in a C program is written as a separate statement. Therefore a complete C program would comprise of a series of statements.

2.The statements in a program must appear in the same order in which we wish them to be executed; unless of course the logic of the problem demands a deliberate ‘jump’ or transfer of control to a statement, which is out of sequence.

3.Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable,constant or keyword.

4.All statements are entered in small case letters. C has no specific rules for the position at which a statement is to be written. That’s why it is often called a free-form language.

5.Every C statement must end with a ;. Thus ; acts as a statement terminator.

C Instructions:-

There are basically three types of instructions in C:

1.Declaration Instruction 2.Arithmetic Instruction 3.Control Instruction

The purpose of each of these instructions is given below:

1.declaration instruction:-

To declare the type of variables used in a C program.

2.Arithmetic instruction:-

To perform arithmetic operations between constants and variables.

3.Control instruction:-

To control the sequence of execution of various statements in a C program.

Declaration Instruction:-

This instruction is used to declare the type of variables being used in the program.

Any variable used in the program must be declared before using it in any statement.

The type declaration statement is written at the beginning of main( ) function.

Ex.: int bas ;

float rs, grosssal ;

char name, code ;

-While declaring the type of variable we can also initialize it as shown below.

int i = 10, j = 25 ;

float a = 1.5,b = 1.99 + 2.4 * 1.44 ;

Arithmetic Instruction:-

A C arithmetic instruction consists of a variable name on the left hand side of = and variable names & constants on the right hand side of =.

The variables and constants appearing on the right hand side of = are connected by arithmetic operators like +, -, *, and /.

Ex.:

int ad ;

float kot, deta, alpha, beta, gamma ;

ad = 3200 ;

kot = 0.0056 ;

deta = alpha * beta / gamma + 3.2 * 2 / 5 ;

Control Instructions in C:-

As the name suggests the ‘Control Instructions’ enable us to specify the order in which the various instructions in a program are to be executed by the computer.

In other words the control instructions determine the ‘flow of control’ in a program. There are four types of control instructions in C.

(a) Sequence Control Instruction

(b) Selection or Decision Control Instruction

(c) Repetition or Loop Control Instruction

(d) Case Control Instruction

The decision control instruction.

The if Statement :-

Like most languages, C uses the keyword if to implement the decision control instruction. The general form of if statement looks like this:

if ( this condition is true ) execute this statement ;

Variations in if statement:-

if(condition)

Statement 1;

Statement 2;

Here only Statement 1 will run if condition is true.

if(condition)

{

Statement 1;

Statement 2;

}

Here all Statements within bracket will run if condition is true.

if(condition)

{

if(condition)

{

Statement 1;

Statement 2;

}

}

We can use if statement within if statement.

The if-else Statement

The if statement by itself will execute a single statement, or a group of statements, when the

main( )

{ int m1, m2, m3, m4, m5, per ; per = ( m1+ m2 + m3 + m4+ m5 ) / per ; if( per >= 60 ) printf ( "First division" ) ; else if( per >= 50 ) printf ( "Second division" ) ;

else if( per >= 40 )

printf ( "Third division" ) ; else

printf ( "fail" ) ;

}

You can note that this program reduces the indentation of the statements. In this case every else is associated with its previous if. The last else goes to work only if all the conditions fail. Even in else if ladder the last else is optional.

Note that the else if clause is nothing different. It is just a way of rearranging the else with the if that follows it.

The! NOT operator

The NOT operator is often used to reverse the logical value of a single variable, as in the expression

! ( y < 10 )

This means “not y less than 10”. In other words, if y is less than 10, the expression will be false, since ( y < 10 ) is true. We can express the same condition as

( y >= 10 ).