CSE100
Introduction to C Programming
Prof. Kuntal Patel
Ahmedabad University
Topics to be covered
• Introduction to C
Features
• What is C used for?
• C vs. Other languages
• Writing First C Program
• Process of Compilation and Execution
• Required Software Environment
• Basics of C Identifiers and Keywords
Introduction to C
• Dennis Ritchie – AT&T Bell Laboratories – 1972
• Widely used today
• Embedded Systems, OS, IoT, Kernel Programming, etc.
• Extends to newer system architectures
• Efficiency / performance
• Low-level access to the system components
Versions of C
• Evolved over the years: 1972 – C invented
• 1978 – C Programming Language specification published
• 1989 – C89 standard (known as ANSI C or Standard C)
• 1990 – ANSI C adopted by ISO, known as C90
• 1999 – C99 standard
• mostly backward-compatible but not completely implemented in
many compilers
• 2007 – new C standard C1X announced (also known as C11)
• The latest Standard - ISO/IEC 9899:2018
• In this course: ANSI/ISO C onwards standard
Reference: https://en.wikipedia.org/wiki/C11_(C_standard_revision)
Latest Standard: https://www.iso.org/standard/74528.html
Importance of C
Use of C Language
Systems programming:
• OSes, like Linux
• microcontrollers: automobiles and airplanes
• Embedded processors: phones, portable electronics, etc.
• DSP processors: digital audio and TV systems...
C Language - Important features
• Based on Few pre-defined Keywords
• Structures, unions – compound data types
• Pointers for memory and arrays management
• External standard library – I/O
• Compiles to native code
• Macro preprocessor
C vs. Other related languages
More recent derivatives of C:
C++, Objective C, C#
Influenced: Java, Perl, Python (quite different)
C lacks:
exceptions
range-checking
garbage collection• object-oriented programming
polymorphism...
Important issues in C
• It’s Low-level language - faster code execution (usually)
• No range checking
• Limited type safety at compile time
• No type checking at runtime
My first C Program - Demonstration
• You need IDE for writing, compiling and debugging C Program
• Program - Filename Extension is Always .c
• Our IDE – Dev C++ -> Editable directly in Dev C++
• Demonstration – Process of Compilation and Execution
IDE – all-in-one solution
• Popular IDEs are: Dev C++, CodeBlocks, Eclipse,
Microsoft Visual C++ (Express Edition), Xcode, . . .
• All are Integrated editor with compiler and debugger
• Very convenient for larger programs
Structure of C Program
/* Begin with comments about C Program, Authors details */
Insert #include statements and preprocessor definitions
Function prototypes and global variable declarations
Define main() function
{
Function body – statements/logic of main
}
Define other function
{
Function body - statements/logic of other function
}
……..
About Comments
Single line comments
// this is a simple comment
OR
/* this is a simple comment */
Multiple lines comments
/ ∗ This comment
Spans multiple lines ∗ /
• Completely ignored by compiler
• Can appear almost anywhere
/* First C program at SEAS – AU by Kuntal Patel */
The #include macro
• Header files: constants, functions, other declarations
• #include <stdio.h> – read the contents of the header file stdio.h
• stdio.h: standard I/O functions for console, files with basic input
and output (I/O) facilities
• stdio.h – part of the C Standard Library
• other important header files: math.h, stdlib.h, string.h, time.h
• Demonstration
Basics of C Identifiers and Keywords
Identifier naming rules in c
• Discussion and demonstrations
Topics covered
Key topics covered during session:
Importance of C Language
IDEs
How to edit, compile, and debug C programs
C programming fundamentals:
comments
preprocessor macros, including #include
Structure of C Program
the main() function
Rules of Identifiers