0% found this document useful (0 votes)
46 views

Computer Languages Are The Languages Through Which The User Can Communicate With The Computer by Writing Program Instructions

C is a programming language used to write programs that communicate with computers. The C program execution process involves writing source code in a .c file, compiling it using a compiler to generate an object code file, linking the object code with libraries to create an executable file, and running the executable file on a CPU. C has a rich set of characters including alphabets, digits, and special symbols that are used to write program instructions. Key elements of a C program include keywords, identifiers, constants, and operators. Input/output functions like printf() and scanf() are used to display output and take user input.

Uploaded by

Krishna Rohith
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Computer Languages Are The Languages Through Which The User Can Communicate With The Computer by Writing Program Instructions

C is a programming language used to write programs that communicate with computers. The C program execution process involves writing source code in a .c file, compiling it using a compiler to generate an object code file, linking the object code with libraries to create an executable file, and running the executable file on a CPU. C has a rich set of characters including alphabets, digits, and special symbols that are used to write program instructions. Key elements of a C program include keywords, identifiers, constants, and operators. Input/output functions like printf() and scanf() are used to display output and take user input.

Uploaded by

Krishna Rohith
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Computer languages are the languages through which the user can

communicate with the computer by writing program instructions.


C Program Execution Process

Source Code Compiler Object Code Linker Executable Code User Screen

abc ALT+F9 add 110 CRTL+F9 ALT+F5

CPU

Sample.obj Sample.exe
Sample.c

stdio.h

List of ERRORS

Header Files
4
Brief History of C
• The C programming language was developed in the Bell Labs of AT&T
by an employee called Dennis Ritchie between 1969 and 1973 while
working on Unix operating system. He created this language
using ALGOL, BCPL, and B the languages that were used before C was
created.
• Ritchie added many powerful features to C and used it to further
develop the UNIX operating system. American National Standards
Institute (ANSI) in 1983, formed a committee to provide a
comprehensive definition to the C language and thus came into
existence the new ANSI C language with better features.
What is C Character set?

C Character set is a collection of characters


supported in C programming language.

C Programming language has a rich set of characters


which are used to construct c program instructions.

1
What does C Character Set contains?
Alphabets
- C Language supports all alphabets of English. It supports
both UPPERCASE & lowercase letters

Digits
- C Language supports 10 digits to construct numbers. Those
10 digits are 0,1,2,3,4,5,6,7,8,9
Special Symbols
- C supports a rich set of special symbols that include symbols
to perform mathematical operations, condition checking,
white space, back space, etc… 2
Commonly used Special Symbols with ASCII Values

3
C Tokens:
In C programs, each word and punctuation is referred to as a token.
C Tokens are the smallest building block or smallest unit of a C program.
Keywords
• Keywords are pre-defined words in a C compiler.
• Each keyword is meant to perform a specific function in a C program.
• Since keywords are referred names for compiler, they can’t be used as
variable name.
• C language supports 32 keywords which are given below. 
C Identifiers
• Identifier refers to name given to entities such as variables, functions,
structures etc.

• Identifiers must be unique. They are created to give a unique name to an


entity to identify it during the execution of the program. For example:
 int money;
 double accountBalance;
• Here, money and accountBalance are identifiers.

• Also remember, identifier names must be different from keywords. You


cannot use int as an identifier because int is a keyword.
• Rules for naming identifiers
o First character must be an alphabet (or underscore).
o Must consist of only letters(a-z,A-Z), digits(0-9) or underscore.
o Only first 31 characters are significant.
o Cannot use a Keyword.
o Must not contain white space.
Constants
• C Constants are also like normal variables. But, only difference is, their
values can not be modified by the program once they are defined.
• Const in c ref to fixd vals that donot alter during ex of prog.
• Constants refer to fixed values. They are also called as literals
• Constants may be belonging to any of the data type.

Syntax:
const type constant_name;
• TYPES OF C CONSTANT:
• Integer constants
• Real or Floating point constants
• Octal & Hexadecimal constants
• Character constants
• String constants
• Backslash character constants
By definition, a constant is a quantity that does not change
throughout the execution of a program.
Integer Constants
An integer constant is an integer quantity which contains a
sequence of digits.It should not have a decimal point. Blanks
and commas are not allowed within an integer constant.An
integer constant can be either +ve or -ve. The constant must lie
within the range of the declared data type (including qualifiers
long,short etc.).
Example of valid integer constants:- 976    8987   5   -25  etc.

Example of invalid integer constants:-  78.43   7-8   89,76  etc.


An integer constant can be either Decimal, Hexa Decimal or
Octal. See the table below to understand how these 3 different
constants are defined in C.
•A decimal constant can contain any combination of integers
from 0 through 9. Ex: 189      0      75       87
Integer Type Prefix Suffix Example •A hexa decimal constant should begin with 0X or 0x. Ex: 0x65F 
Hexa Decimal Ox   OxA7B or 0X7A
Octal O   O54
Long Hexa Decimal Ox I or L OxA7BL •An octal constant should begin with digit 0. It can take any
Unsigned Long Ox UI or UL OxA7FUI digits from 0 through 7.
Hexa Decimal Note:- There is no binary integer constant in C by default. This
Long Octal O I or L O54L means, you cant give a binary number directly to program by
writing sth like:- 0b11001011 – which is meaningless and result
in an error. How ever, programmer can add a preprocessor
(which we will learn later) to accept binary numbers in a
program.
Floating Point Constants
They are also known as real constants. A real constant contains
a decimal point or an exponent. It can be either +ve or -ve.
Commas and blank space are not allowed within a real
constant.
Examples:– 254.175,      -16.47      -0.5e-7     +4.1e8
Character Constant
A character constant is a character which is enclosed in single
quotes. A character constant is of size 1byte and can contain
only 1 character. A character can be an alphabet like a,b,A,C etc
or a special character like &,^, $, #,@ etc or a single digit from 0
through 9. It can also be an escape sequence character like
space ‘ ‘ or a null character ‘\o’  or  a new line ‘\n’  etc

Example: ‘A’       ‘a’     ‘ b’      ‘8’     ‘#’  etc.

String Constants
1. A string constant is a collection of characters enclosed
in double quotations “”
2. It may contain alphabets, digits, special characters and
blank space.
Example:   “Circuits Today123”
Datatypes:
Void Types:

The void type has no values. It is used to represent the type of function. The
type of function is said to be void when it does not return any value to the calling
function.
Variables in C
• A variable is nothing but a name given to a storage area that our
programs can manipulate.
• A variable definition tells the compiler where and how much storage to
create for the variable.
• A variable definition specifies a data type and contains a list of one or
more variables of that type as follows −
Syntax:
type variable_list;
Ex:int i, j, k;
char c, ch;
float f, salary;
double d;
type variable_name = value;

extern int d = 3, f = 5; // declaration of d and f.


int d = 3, f = 5; // definition and initializing d and f.
char x = 'x'; // the variable x has the value 'x'.
Input/Output
• Input means to provide the program with some data to be used in the
program and Output means to display data on screen or write the data
to a printer or a file.
• The standard input-output header file, named stdio.h contains the
definition of the functions printf() and scanf(), which are used to display
output on screen and to take input from user respectively.
printf()
• The printf() method, in C, prints the value passed as the parameter to
it, on the console screen.

printf(“%X”, variableOfXType);
• where %X is the format specifier in C. It is a way to tell the compiler
what type of data is in a variable
scanf()
• The scanf() method, in C, reads the value from the console as per the
type specified.
scanf(“%X”, &variableOfXType);
• where %X is the format specifier in C.
• It is a way to tell the compiler what type of data is in a variable
• & is the address operator in C, which tells the compiler to change the
real value of this variable, stored at this address in the memory.
C – Operators
• The symbols which are used to perform logical and mathematical
operations in a C program are called C operators.
• These C operators join individual constants and variables to form
expressions.
• Operators, functions, constants and variables are combined together
to form expressions.
• Consider the expression A + B * 5. where, +, * are operators, A, B  are
variables, 5 is constant and A + B * 5 is an expression.
Expressions
•  An expression is a combination of operators, constants and variables.
An expression may consist of one or more operands, and zero or more
operators to produce a value.
Precedence and Associativity
• The symbols which are used to perform logical and mathematical
operations in a C program are called C operators.
• These C operators join individual constants and variables to form
expressions.
• Operators, functions, constants and variables are combined together
to form expressions.
• Consider the expression A + B * 5. where, +, * are operators, A, B  are
variables, 5 is constant and A + B * 5 is an expression.
Different types of operators
• Arithmetic operators
• Assignment operators
• Relational operators
• Logical operators
• Bit wise operators
• Conditional operators (ternary operators)
• Increment/decrement operators
• Special operators
Assignment
Operators
Relational
Operators
Logical Operators
big = a > b ? (a > c ? a : c) : (b > c ? b : c) ;
Increment/decrement operators
Operator Precedence in C
Operator precedence determines which operator is evaluated first when an expression has more than one operators.
Operators Associativity

• Operators Associativity is used when two operators of same


precedence appear in an expression. Associativity can be
either Left to Right or Right to Left.
• For example multiplication and division arithmetic operators have
same precedence, lets say we have an expression 5*2/10, this
expression would be evaluated as (5*2)/10 because the associativity
is left to right for these operators. 
Evaluating Expressions
• In the C programming language, an expression is evaluated based on
the operator precedence and associativity.
• When there are multiple operators in an expression, they are
evaluated according to their precedence and associativity.
• The operator with higher precedence is evaluated first and the
operator with the least precedence is evaluated last.
10 + 4 * 3 / 2
4 * 3 ====> 12
12 / 2 ===> 6
10 + 6 ===> 16
The expression is evaluated to 16.
Write a C Program to evaluate
x= a-b/3+c*2-1;
y= a-b/(3+c)*(2-1);
z=a-(b/(3+c)*2)-1;
Type Conversion
• Type casting refers to changing a variable of one data type into
another.
• Two Types
Implicit Type Conversion
Explicit Type Conversion
Advantages of Type Conversion
• This is done to take advantage of certain features of type hierarchies
or type representations.
• It helps us to compute expressions containing variables of different
data types.
Implicit Type Conversion
• When the type conversion is performed automatically by the compiler
without programmers intervention, such type of conversion is known
as implicit type conversion or type promotion.
int x;
If(x>0)
{
printf("%c", x); /*Implicit casting from int to char %c*/
}
Explicit Type Conversion
• The type conversion performed by the programmer by posing the
data type of the expression of specific type is known as explicit type
conversion. The explicit type conversion is also known as type casting.
• Type casting in c is done in the following form:
(data_type)expression;

where, data_type is any valid c data type, and expression may be


constant, variable or expression.
int x;
If(x>0)
{
printf("%c", (char)x); /*Explicit casting from int to char*/
}
Example of Typecasting
int x=7, y=5 ;
float z;
z=x/y; /*Here the value of z is 1*/
If we want to get the exact value of 7/5 then we need explicit casting from int to
float:
int x=7, y=5;
float z;
z = (float)x/(float)y; /*Here the value of z is 1.4*/
Whenever two operands of different data types are involved in an expression, the
operand of lower rank will be converted to a data type of higher rank. This
process is called the promotion of type.
#include<stdio.h>
void main()
{
int a = 25, b = 13;
float result;
result = a/b;
// display only 2 digits after decimal point
printf("(Without typecasting) 25/13 = %.2f\n", result );
result = (float)a/b;
// display only 2 digits after decimal point
printf("(With typecasting) 25/13 = %.2f\n", result );
getch();
Two-way selection
• The two-way selection is the basic decision statement for computers.
• The decision is based on resolving a binary expression, and then
executing a set of commands depending on whether the response
was true or false.
• C, like most contemporary programming languages, implements two-
way selection with the if…else statement.
• An if…else statement is a paired statement used to selectively execute
code based on two alternatives.

You might also like