Introduction to C
Programming
Agenda
Introduction to C Programming
•History of C Language
•Features and Applications of C Language
•Basic Structure of a C Program
•Compilation and Linking Process
•Constants, Variables, and Data Types
•Operators in C
•Precedence and Associativity of Operators
● Developed by Dennis Ritchie in 1972 at Bell Laboratories.
● General-purpose high-level language, influenced by BCPL.
● Known for its ease of learning and structured approach.
● Produces efficient programs capable of handling low-level operations.
● Highly portable and can be compiled on various computer systems.
Key Characteristics of C
Programming
Introduction to C Programming
Overview
 The C programming language was developed by Dennis Ritchie at AT&T's Bell Laboratories in 1972.
 It evolved from the earlier language BCPL (Basic Combined Programming Language), created by Martin
Richards.
 C is classified as a middle-level language because it bridges the gap between low-level assembly languages
and high-level programming languages.
 This middle-level nature allows C to efficiently handle system-level tasks such as operating system
development while also supporting higher-level programming constructs.
 The versatility and efficiency of C have made it a foundational language in computer science, influencing
many subsequent languages and becoming a core tool for system programming, compiler construction, and
embedded systems.
History of C Language
Introduction
Features and Applications of C Language
Overview
C is versatile and can be used for system
programming, game development, real-time
systems, and embedded systems.
C supports structured programming, allowing
complex programs to be broken down into
simpler, manageable modules.
C programs are highly portable and can be
compiled and run on various computer
architectures with minimal changes.
General-Purpose Language
Structured Programming
Portability
C provides powerful functions for dynamic
memory allocation, enabling flexible and
efficient management of memory during
runtime.
Dynamic Memory Allocation
Programs written in C are highly efficient,
making optimal use of system resources. It is
suitable for developing performance-critical
applications.
Efficiency
C offers a wide range of operators to perform
various operations, making it a robust
language for different types of programming
tasks.
Rich Set of Operators
Documentation and
Preprocessor
Definition and Global
Declarations
Main Function and
Subprograms
The Documentation section
includes comments that describe the
program.
The Preprocessor section
contains preprocessor directives like
#include <stdio.h>.
The Definition section defines
symbolic constants using #define.
Global Declarations include variables
that are accessible throughout the
program.
The main() function is the entry
point of a C program. It includes
Declarations and Execution parts.
Subprograms contain user-defined
functions called within main().
Basic Structure of a C Program
Program Structure
Typing the Program Compiling
Translating to
Assembly
Linking and
Executing
The source code is typed into a file using
a text editor. The file typically has a .c
extension, e.g., prog1.c. This source code
file contains human-readable
instructions written in C.
The source code is compiled using a
compiler like gcc. During this step, the
compiler checks for syntax and semantic
errors, and translates the code into
assembly language if no errors are found.
The compiler translates each statement
into assembly language, which is then
converted to machine code by the
assembler. This machine code is stored in
an object file with a .o extension.
The linker combines the object file with
libraries and other resources to create an
executable. This file can then be run on
the computer to perform the
programmed tasks.
Source code file (e.g., prog1.c) Assembly code file (e.g., prog1.s) Object code file (e.g., prog1.o) Executable file (e.g., a.out or
prog1.exe)
Compilation and Linking Process
Process Plus tip:
This slide can be customized by adding
specific commands used for eac step
on different operating systems, such
as Unix or Windows.
Constants Variables Data Types
Constants are fixed values that do
not change during program
execution. They include numeric
constants (integers, reals), character
constants (single characters in single
quotes), and symbolic constants
(defined using #define or const).
Variables are named memory
locations whose values can change
during execution. They are declared
with a specific data type and can be
assigned values using the assignment
operator. Example: int age = 25;
Data types define the type of data
a variable can hold. Primary data
types include int, float, double, and
char. Derived data types include
arrays and pointers. User-defined
data types include structs and
unions.
Constants, Variables, and Data Types
Overview
Operators in C
Operators
Used for performing mathematical operations
like addition, subtraction, multiplication,
division, and modulo. Examples: +, -, *, /, %.
Used to compare two values. Examples
include: < (less than), > (greater than), ==
(equal to), <= (less than or equal to), >=
(greater than or equal to), != (not equal to).
Used to assign values to variables. Examples:
= (simple assignment), += (add and assign), -
= (subtract and assign), *= (multiply and
assign), /= (divide and assign), %= (modulus
and assign).
Arithmetic Operators
Relational Operators
Assignment Operators
Used to perform bit-level operations.
Examples: & (bitwise AND), | (bitwise OR), ^
(bitwise XOR), ~ (bitwise NOT), << (left
shift), >> (right shift).
Bitwise Operators
Used to combine multiple conditions.
Examples: && (logical AND), || (logical OR), !
(logical NOT).
Logical Operators
Used with only one operand. Examples: ++
(increment), -- (decrement), sizeof (size of
variable), & (address of), * (value at address).
Unary Operators
 In C programming, operator precedence determines the order in which parts of a complex
expression are evaluated.
 Operators with higher precedence are evaluated before operators with lower precedence.
Associativity defines the order in which operators of the same precedence are processed.
 Most operators in C have left-to-right associativity, meaning they are evaluated from left to
right. For instance, in the expression `a + b * c`, the multiplication operator (`*`) has higher
precedence than the addition operator (`+`), so `b * c` is evaluated first.
 Parentheses can be used to explicitly specify the order of evaluation, overriding precedence
rules.
Precedence and Associativity of Operators
Operators
Thank you.

Introduction to C Programming fjhjhjh.pptx

  • 1.
  • 2.
    Agenda Introduction to CProgramming •History of C Language •Features and Applications of C Language •Basic Structure of a C Program •Compilation and Linking Process •Constants, Variables, and Data Types •Operators in C •Precedence and Associativity of Operators
  • 3.
    ● Developed byDennis Ritchie in 1972 at Bell Laboratories. ● General-purpose high-level language, influenced by BCPL. ● Known for its ease of learning and structured approach. ● Produces efficient programs capable of handling low-level operations. ● Highly portable and can be compiled on various computer systems. Key Characteristics of C Programming Introduction to C Programming Overview
  • 4.
     The Cprogramming language was developed by Dennis Ritchie at AT&T's Bell Laboratories in 1972.  It evolved from the earlier language BCPL (Basic Combined Programming Language), created by Martin Richards.  C is classified as a middle-level language because it bridges the gap between low-level assembly languages and high-level programming languages.  This middle-level nature allows C to efficiently handle system-level tasks such as operating system development while also supporting higher-level programming constructs.  The versatility and efficiency of C have made it a foundational language in computer science, influencing many subsequent languages and becoming a core tool for system programming, compiler construction, and embedded systems. History of C Language Introduction
  • 5.
    Features and Applicationsof C Language Overview C is versatile and can be used for system programming, game development, real-time systems, and embedded systems. C supports structured programming, allowing complex programs to be broken down into simpler, manageable modules. C programs are highly portable and can be compiled and run on various computer architectures with minimal changes. General-Purpose Language Structured Programming Portability C provides powerful functions for dynamic memory allocation, enabling flexible and efficient management of memory during runtime. Dynamic Memory Allocation Programs written in C are highly efficient, making optimal use of system resources. It is suitable for developing performance-critical applications. Efficiency C offers a wide range of operators to perform various operations, making it a robust language for different types of programming tasks. Rich Set of Operators
  • 6.
    Documentation and Preprocessor Definition andGlobal Declarations Main Function and Subprograms The Documentation section includes comments that describe the program. The Preprocessor section contains preprocessor directives like #include <stdio.h>. The Definition section defines symbolic constants using #define. Global Declarations include variables that are accessible throughout the program. The main() function is the entry point of a C program. It includes Declarations and Execution parts. Subprograms contain user-defined functions called within main(). Basic Structure of a C Program Program Structure
  • 7.
    Typing the ProgramCompiling Translating to Assembly Linking and Executing The source code is typed into a file using a text editor. The file typically has a .c extension, e.g., prog1.c. This source code file contains human-readable instructions written in C. The source code is compiled using a compiler like gcc. During this step, the compiler checks for syntax and semantic errors, and translates the code into assembly language if no errors are found. The compiler translates each statement into assembly language, which is then converted to machine code by the assembler. This machine code is stored in an object file with a .o extension. The linker combines the object file with libraries and other resources to create an executable. This file can then be run on the computer to perform the programmed tasks. Source code file (e.g., prog1.c) Assembly code file (e.g., prog1.s) Object code file (e.g., prog1.o) Executable file (e.g., a.out or prog1.exe) Compilation and Linking Process Process Plus tip: This slide can be customized by adding specific commands used for eac step on different operating systems, such as Unix or Windows.
  • 8.
    Constants Variables DataTypes Constants are fixed values that do not change during program execution. They include numeric constants (integers, reals), character constants (single characters in single quotes), and symbolic constants (defined using #define or const). Variables are named memory locations whose values can change during execution. They are declared with a specific data type and can be assigned values using the assignment operator. Example: int age = 25; Data types define the type of data a variable can hold. Primary data types include int, float, double, and char. Derived data types include arrays and pointers. User-defined data types include structs and unions. Constants, Variables, and Data Types Overview
  • 9.
    Operators in C Operators Usedfor performing mathematical operations like addition, subtraction, multiplication, division, and modulo. Examples: +, -, *, /, %. Used to compare two values. Examples include: < (less than), > (greater than), == (equal to), <= (less than or equal to), >= (greater than or equal to), != (not equal to). Used to assign values to variables. Examples: = (simple assignment), += (add and assign), - = (subtract and assign), *= (multiply and assign), /= (divide and assign), %= (modulus and assign). Arithmetic Operators Relational Operators Assignment Operators Used to perform bit-level operations. Examples: & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), >> (right shift). Bitwise Operators Used to combine multiple conditions. Examples: && (logical AND), || (logical OR), ! (logical NOT). Logical Operators Used with only one operand. Examples: ++ (increment), -- (decrement), sizeof (size of variable), & (address of), * (value at address). Unary Operators
  • 10.
     In Cprogramming, operator precedence determines the order in which parts of a complex expression are evaluated.  Operators with higher precedence are evaluated before operators with lower precedence. Associativity defines the order in which operators of the same precedence are processed.  Most operators in C have left-to-right associativity, meaning they are evaluated from left to right. For instance, in the expression `a + b * c`, the multiplication operator (`*`) has higher precedence than the addition operator (`+`), so `b * c` is evaluated first.  Parentheses can be used to explicitly specify the order of evaluation, overriding precedence rules. Precedence and Associativity of Operators Operators
  • 11.