Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views26 pages

Fundamentals of C Programming

The document provides an introduction to the C programming language, detailing its history, key features, and foundational concepts such as tokens, identifiers, keywords, constants, variables, data types, expressions, statements, and library functions. It highlights the significance of C as a structured, portable, and versatile language developed in 1972 by Dennis Ritchie at AT&T's Bell Laboratories. Additionally, it discusses the rules for naming identifiers and variables, as well as the role of preprocessor directives in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

Fundamentals of C Programming

The document provides an introduction to the C programming language, detailing its history, key features, and foundational concepts such as tokens, identifiers, keywords, constants, variables, data types, expressions, statements, and library functions. It highlights the significance of C as a structured, portable, and versatile language developed in 1972 by Dennis Ritchie at AT&T's Bell Laboratories. Additionally, it discusses the rules for naming identifiers and variables, as well as the role of preprocessor directives in C programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Fundamentals of

C-Programming
Dr. Asra Sadaf
Dept. of Computer Science & Engineering
[email protected]
Room no: 622
Surprise:
Introduction to C:
• C is a programming language developed at AT & T’s Bell Laboratories
of USA in 1972.
1960: ALGOL (ALGOrithmic Language)
1967: BCPL (Basic Combined Programming Language)
1970: B programming language (typeless)
1972: C: BCPL plus B with types
1978: Kernighan + Ritchie standard for C
1989: ANSI standard for C
Contd.
• It was designed and written by Dennis Ritche. Dennis Ritchie is known
as the founder of c language.
• Initially, C language was developed to be used in UNIX operating
system.
• Portability or machine independent
• Sound and versatile language
• Fast program execution.
• An extendible language.
• Tends to be a structured language.
Flow of a Language:
C TOKENS:
• The smallest individual units are known as tokens. C has six types of
tokens.
• 1: Identifiers
• 2: Keywords
• 3: Constants
• 4: Strings
• 5: Special Symbols
• 6: Operators
1: Identifiers
• Identifiers refer to the names of variables, constants, functions and
arrays. These are user-defined names is called Identifiers. These
identifier are defined against a set of rules.
Rules for an Identifier
1. An Identifier can only have alphanumeric characters( a-z , A-Z , 0-9 ) and
underscore( _ ).
2. The first character of an identifier can only contain alphabet( a-z , A-Z ) or
underscore ( _ ).
3. Identifiers are also case sensitive in C. For example name and Name are
two different identifier in C
4. Keywords are not allowed to be used as Identifiers.
5. No special characters, such as semicolon, period, whitespaces, slash or
comma are permitted to be used in or as Identifier.
6. C compiler recognizes only the first 31 characters of an identifiers.
2: Keywords
• A keyword is a reserved word.
• All keywords have fixed meaning that means we cannot change.
• Keywords serve as basic building blocks for program statements.
• All keywords must be written in lowercase. A list of 32 keywords in c language is
given below:
3: Constants
• Constants refer to fixed values that do not change during the
execution of a program.
• Note: constants are also called literals.
Define constant in C
• There are two ways to define constant in C programming.
• 1. const keyword 2. #define preprocessor
const float PI=3.14;
#include<stdio.h>
#define PI 3.14
#include<stdio.h> main()
#include<conio.h> {
void main() printf("%f",PI);
{ }
const float PI=3.14;
clrscr();
printf("The value of PI is: %f",PI); Output: 3.140000
getch();
}
Output:
The value of PI is: 3.140000
4: Strings or Variable
• A variable is a name of memory location. It is used to store data.
Variables are changeable, we can change value of a variable during
execution of a program.
• It can be reused many times.
• The rule for naming the variables is same as the naming identifier.
• Syntax : data_type variable-1,variable-2,------, variable-n;
Assigning values to variables:
• Values can be assigned to variables using the assignment operator (=).
• The general format statement is :
• Syntax : variable = constant;
• Ex :
• int x=100;
• float a= 12.25;
• char m=‟f‟;
Types of Variables in C
• There are many types of variables in c:
• 1. local variable
• 2. global variable
• 3. static variable
Special Symbols
Data Types in C
• Each variable in C has an associated data type. It specifies the type of
data that the variable can store like integer, character, floating,
double, etc.
• C is a statically type language where each variable's type must be
specified at the declaration and once specified, it cannot be
changed.
Classification
Basic Data Type
Integer Data Type Character Data Type
The integer datatype in C is used to Character data type allows its variable
store the integer numbers (any number to store only a single character. The size
including positive, negative and zero of the character is 1 byte. It is the most
without decimal part). Octal values, basic data type in C. It stores a single
hexadecimal values, and decimal values character and requires a single byte of
can also be stored in int data type in C. memory in almost all compilers.

Float Data Type Double Data Type


In C programming, float data type is The double data type in C is used to store
used to store single precision decimal numbers (numbers with floating
floating-point values. These values point values) with double precision. It can
are decimal and exponential easily accommodate about 16 to 17 digits
numbers. after or before a decimal point.
Memory allocation of basic data type
Expressions:
• An expression is a combination of operators, operands, and function
calls that evaluates to a single value.

• Expressions can be simple (e.g., 5, x) or complex (e.g., a + b * 2,


sqrt(x)).
• The type of the resulting value depends on the types of the operands
and the operators used.
Statement:
• A statement is a complete instruction that performs an action.
• It typically ends with a semicolon (;) in C/C++. Statements can be:
• Expression statements: An expression followed by a semicolon (e.g., x = 5;,
printf("Hello");).
• Declaration statements: Introduce a new variable or function (e.g., int age;,
void func();).
• Control flow statements: Alter the execution path of a program (e.g., if, for,
while, switch).
• Compound statements (blocks): A sequence of statements enclosed in curly
braces {}.
Library Functions:
• Library functions are pre-defined functions provided as part of a
programming language's standard library.
• They offer common functionalities and are readily available for use by
including the appropriate header files.
• Examples in C include printf() for output, scanf() for input, sqrt() for
square root calculation, and malloc() for dynamic memory allocation.
• These functions save developers from writing common code from
scratch.
Preprocessor:
• The preprocessor is a program that processes the source code before
the actual compilation begins. It performs textual manipulations on
the code based on preprocessor directives. Common preprocessor
directives include:
• Macros (#define): Define symbolic constants or function-like macros
for code substitution.
• File inclusion (#include): Include the content of other files (typically
header files) into the current source file.
Library Functions In C
• Library functions in C are pre-written functions provided by C's
standard library. These functions perform specific tasks, such as
input/output operations, string manipulation, mathematical
calculations, memory allocation, and more.

You might also like