Unit 3: Fundamentals of C Programming | B. Sc Year: III

🧭 Introduction

After learning about programming languages in Unit 2, it’s time to start with an actual language—C programming.

C is one of the most important foundational programming languages, influencing languages like C++, Java, and Python. It is widely used for:

  • Operating systems

  • Embedded systems

  • Compilers

  • System software

This unit introduces the basic building blocks of C programming, essential for exams and for understanding later units.


🔑 Key Concepts (Explained Clearly)


1️⃣ What is C Programming Language?

C is a general-purpose, structured, procedural programming language developed by Dennis Ritchie (1970s) at Bell Labs.

Why C is important:

  • Fast execution

  • Close to hardware

  • Portable (machine-independent)

  • Used for system-level programming

C is often called the mother of programming languages.


2️⃣ Structure of a C Program

A basic C program:

#include <stdio.h>

int main() {
    // Program statements
    return 0;
}

Parts of a C Program:

  1. Preprocessor Directives#include <stdio.h> tells compiler to include required files

  2. main() Function – Entry point of execution

  3. Statements – Instructions executed by the program

  4. Return Statementreturn 0; indicates successful execution


3️⃣ Compilation and Execution

C programs run in two stages:

🛠 Compilation

  • Converts C source code to machine code

  • Checks syntax errors

  • Produces executable file

▶ Execution

  • OS loads the executable

  • Program runs and produces output

Steps:

  1. Preprocessing

  2. Compilation

  3. Linking

  4. Execution


4️⃣ C Character Set

Includes:

  • Letters: A–Z, a–z

  • Digits: 0–9

  • Special Symbols: +, -, *, /, =, <, >, etc.

  • Whitespace: space, tab, newline

These are used to form words, expressions, and statements.


5️⃣ Tokens in C

Tokens = smallest units of a C program.

Types:

  1. Keywords – Reserved words with special meaning

    int, float, if, else, return, for
    
  2. Identifiers – User-defined names

    total, sum, calculate
    
  3. Constants – Fixed values

    10, 3.14, 'A'
    
  4. Operators – Symbols performing operations

    + - * / %
    
  5. Punctuators – Symbols like

    ; , () {} []
    

6️⃣ Keywords and Identifiers

✅ Keywords

  • Predefined words in C

  • Cannot be used as identifiers

  • Example: int if while return

✅ Identifiers

  • Programmer-defined names

  • Rules:

    • Begin with letter or underscore

    • No spaces

    • Case-sensitive

Example:

int age;
float totalMarks;

7️⃣ Variables and Constants

🔹 Variables

  • Store data in memory

Declaration:

int num;

Declaration + Initialization:

int num = 10;

🔹 Constants

  • Values that do not change

Using const:

const int max = 100;

Using #define:

#define PI 3.14

8️⃣ Data Types in C

Basic Data Types:

TypeExample
int5, 10
float3.14
double3.14159
char'A'

Derived Data Types:

  • Array

  • Pointer

  • Structure

  • Union


9️⃣ Expressions and Operators

An expression combines variables, constants, and operators.

int z = a + b * 2;

Operator Precedence (High → Low):

  1. ()

  2. * / %

  3. + -

  4. =


🔟 Statements in C

Types:

  1. Assignment Statement

x = 10;
  1. Input/Output Statement

printf("Hello");
scanf("%d", &x);
  1. Control Statement

if (x > 5) { ... }
  1. Function Call

sqrt(25);

1️⃣1️⃣ Comments in C

Make programs easy to understand.

Single-line:

// This is a comment

Multi-line:

/* This is
   a multi-line
   comment */

Ignored by compiler.


1️⃣2️⃣ Escape Sequence Characters

Special characters for output formatting.

EscapeMeaning
\nNew line
\tTab
\\Backslash
\"Double quote

Example:

printf("Hello\nWorld");

📝 Important Exam Questions

  1. Define keywords and identifiers with examples

  2. Explain structure of a C program

  3. What are tokens in C?

  4. Define variables and constants

  5. Explain data types in C

  6. What are escape sequence characters?

  7. Explain expressions and operator precedence


🧩 Step‑by‑Step Example

Program: Add Two Numbers

#include <stdio.h>

int main() {
    int a = 5, b = 3, sum;
    sum = a + b;
    printf("Sum = %d", sum);
    return 0;
}

Explanation:

  • Variables declared

  • Expression evaluated

  • Result printed


🎯 Exam Tips / Key Points

  • Write program structure neatly

  • Use examples for keywords & identifiers

  • Write 3–4 points for theory answers

  • Programs should have:

    • Header file

    • main() function

    • return 0;

  • Commented programs get extra marks


✅ Short Summary

Unit 3 covers the fundamentals of C programming, including:

  • Structure of a C program

  • Variables, constants, data types

  • Tokens, keywords, identifiers

  • Expressions, statements, comments

This unit forms the base for writing C programs, preparing you for input/output, operators, and control statements in later units.

Netra Koirala

Netra Koirala

Computer Science Educator

Passionate computer science educator and author. Provides free study notes, practical guides, and tutorials for Class 9, 10, 11, 12, and B.Sc CSIT students in Nepal. Years of teaching experience in computer science fundamentals.

Computer Science notes, tutorials, MCQs, and educational resources for Nepal students. Covering Class 9, SEE preparation, Class 11, Class 12, SLC, programming, DBMS, networking, HTML, JavaScript, PHP, OOP and more.

Featured Post

Grade 10 Computer Science: Specification Grid & Model Questions

Specification Grid & Model Questions of Computer Science | Grade 10 📚 Examination Resource Specification Grid & M...

Followers