πŸ“ Lawyer Pet Ext., Ongole, AP πŸ“ž +91 9848517191 βœ‰οΈ support@kkccinfo.com
Official Courseware

C Programming Complete Course Manual

From basic syntax to advanced pointers, matrix operations, functions, storage classes, and structures.

1. History of 'C'

'C' is a powerful programming language which has attracted worldwide adoption because software industries rely on it for high-performance computing. A program written in 'C' can be transferred easily from one computer system to another with minimal or no changes. Programs written in 'C' execute fast and efficiently. This versatility makes 'C' a desirable language in the highly competitive software industry.

A system programmer named Dennis Ritchie developed the 'C' language at Bell Laboratories in early 1972. It was written originally for programming under the Unix operating system. The language derives from earlier work by Ken Thompson, who created the 'B' language based on B.C.P.L (Basic Combined Programming Language). Thompson dubbed his version 'B', and later Dennis Ritchie chose the second letter of B.C.P.Lβ€”'C'β€”to represent the improved successor language.

Genealogy of C Language Development

BCPL (1965-67) βž” B Language (1969) βž” New B (1971) βž” Early C (1972-73)

2. Character Set & Identifiers

'C' uses the following set of valid characters:

  • Letters: Upper case A – Z, Lower case a – z
  • Digits: 0 – 9
  • Special Characters: *, (, ), #, &, [, ], ", ', +, -, <, >, =, _, etc.

Identifiers

Identifiers are names given to various program elements such as variables, functions, and arrays. An identifier consists of letters and digits in any order, except that the first character must be a letter or an underscore (_).

Valid Identifiers Invalid Identifiers Reason for Invalidity
Temp 8level Cannot start with a digit
_78po cust name Cannot contain spaces
total_sum sum-total Hyphen (-) is an operator

3. Keywords (Reserved Words)

Reserved words in 'C' are called keywords. These keywords have predefined meanings to the compiler and cannot be used as user-defined identifiers. All reserve words must be written in lower case letters.

auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while

4. Data Types, Sizes & Ranges

'C' provides several basic data types along with qualifiers (short, long, signed, unsigned):

Data Type Size (Bytes) Range
char or signed char 1 -128 to 127
unsigned char 1 0 to 255
int or signed int 2 -32,768 to 32,767
unsigned int 2 0 to 65,535
short int 1 -128 to 127
unsigned short int 1 0 to 255
long int 4 -2,147,483,648 to 2,147,483,647
unsigned long int 4 0 to 4,294,967,295
float 4 3.4e-38 to 3.4e+38
double 8 1.7e-308 to 1.7e+308
long double 10 3.4e-4932 to 1.1e+4932

5. Constants & Escape Sequences

'C' has four basic types of constants: Integer constants, Floating point constants, Character constants (enclosed in single quotes `'a'`), and String constants (enclosed in double quotes `"srinivas"`).

Escape Sequences Table

An escape sequence begins with a backslash (\) followed by special control characters:

Character Escape Sequence ASCII Value
Bell (Alert)\a007
Backspace\b008
Horizontal Tab\t009
Vertical Tab\v011
New Line\n010
Form Feed\f012
Carriage Return\r013
Question Mark\?063
Double Quotation Mark\"034
Single Quote\'039
Backslash\\092
Null Character\0000

6. Variables & Declarations

A variable is a named memory location used to represent specified information. Variables must be declared before they are used in executable statements.

Variable Declarations
// Syntax: data_type variable1, variable2;
int a, b, c;
char ch;
float sum;

// Variable Initialization
int value = 5;
char name[10] = "srinivas";

7. Operators & Expressions

A. Arithmetic Operators

+ (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus - remainder after integer division).

B. Relational Operators

< (Less than), > (Greater than), <= (Less than or equal), >= (Greater than or equal), == (Equal to), != (Not equal).

C. Logical & Assignment Operators

Logical: && (AND), || (OR), ! (NOT).
Compound Assignment: +=, -=, *=, /=, %= (e.g. a += 2 is equivalent to a = a + 2).

D. Unary Operators

Operators acting on a single operand: Increment (++), Decrement (--), Size of operator (sizeof).

8. Input/Output (getchar, putchar, printf, scanf)

Conversion Characters for Formatted I/O

SpecifierMeaning / Data Type
%cSingle character
%dSigned decimal integer
%fFloating point decimal number
%eExponential floating point format
%sString of characters
%xHexadecimal integer
%oOctal integer

Program: Reading & Displaying Character

Character I/O
#include <stdio.h>

int main() {
    char a;
    printf("Enter a character: ");
    a = getchar();
    printf("You entered: ");
    putchar(a);
    return 0;
}

9. Branching (If-Else Statements)

The if-else statement evaluates a condition to select between two decision paths.

Even or Odd Program
#include <stdio.h>

int main() {
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);

    if (n % 2 == 0) {
        printf("The number %d is EVEN\n", n);
    } else {
        printf("The number %d is ODD\n", n);
    }

    return 0;
}

10. Looping (While, Do-While, For)

Program: Check Prime Number (While Loop)

Prime Check
#include <stdio.h>

int main() {
    int n, i = 1, count = 0;
    printf("Enter any positive integer: ");
    scanf("%d", &n);

    while (i <= n) {
        if (n % i == 0) {
            count++;
        }
        i++;
    }

    if (count == 2) {
        printf("%d is a Prime Number\n", n);
    } else {
        printf("%d is Not a Prime Number\n", n);
    }

    return 0;
}

Program: Number Pyramid Pattern (For Loop)

Nested For Loops
#include <stdio.h>

int main() {
    int n = 4, i, j;
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= i; j++) {
            printf("%d ", j);
        }
        printf("\n");
    }
    return 0;
}
/* Output:
1
1 2
1 2 3
1 2 3 4
*/

11. Arrays & Multi-Dimensional Matrices

An array is a collection of similar data elements stored in contiguous memory locations.

Program: Matrix Addition (2x2)

2D Matrix Addition
#include <stdio.h>

int main() {
    int a[2][2] = {{1, 2}, {3, 4}};
    int b[2][2] = {{5, 6}, {7, 8}};
    int sum[2][2], i, j;

    for (i = 0; i < 2; i++) {
        for (j = 0; j < 2; j++) {
            sum[i][j] = a[i][j] + b[i][j];
            printf("%d\t", sum[i][j]);
        }
        printf("\n");
    }
    return 0;
}

12. Strings & String Library Functions

A string in 'C' is a 1D character array terminated by a null character (\0). Standard string functions in <string.h>:

  • strcpy(dest, src) - Copies string src into dest.
  • strcat(str1, str2) - Appends str2 to the end of str1.
  • strcmp(str1, str2) - Compares two strings (returns 0 if identical).
  • strrev(str) - Reverses the characters in a string.

13. Goto & Unconditional Statements

Multiplication Table using Goto
#include <stdio.h>

int main() {
    int n = 5, i = 1;
    loop_start:
    printf("%d x %d = %d\n", n, i, n * i);
    i++;
    if (i <= 10) {
        goto loop_start;
    }
    return 0;
}

14. Switch Case Statement

Menu-Driven Calculator
#include <stdio.h>

int main() {
    int a = 10, b = 5, choice = 1;

    switch(choice) {
        case 1: printf("Addition: %d\n", a + b); break;
        case 2: printf("Subtraction: %d\n", a - b); break;
        default: printf("Invalid choice\n"); break;
    }
    return 0;
}

15. Functions & Modular Programming

Functions allow breaking programs into modular, reusable blocks.

Function Call by Value
#include <stdio.h>

int calculateArea(int length, int width) {
    return length * width;
}

int main() {
    int area = calculateArea(12, 5);
    printf("Area of Rectangle: %d\n", area);
    return 0;
}

16. Storage Classes in C

Storage classes determine the scope, lifetime, and initial value of variables:

  • auto: Local variable created on function entry and destroyed on exit.
  • extern: Global variable accessible across multiple files.
  • static: Retains its current value across multiple function calls.
  • register: Requests compiler to store variable in fast CPU registers.

17. Structures & Dynamic Memory

C Structure & Pointers
#include <stdio.h>
#include <string.h>

struct Student {
    char name[50];
    int rollNo;
};

int main() {
    struct Student s1;
    strcpy(s1.name, "Ramu K.");
    s1.rollNo = 101;

    printf("Student: %s, Roll: %d\n", s1.name, s1.rollNo);
    return 0;
}
πŸ“ Unsolved Student Practice Exercises & Homework
  1. Write a program to calculate Simple Interest and display the result.
  2. Write a program to calculate Area (3.1416 * r * r) and Circumference of a Circle.
  3. Write a program to calculate Net Salary (basic=1600, DA=7%, HA=2%, TA=10%).
  4. Write a program to print even numbers between 1 and 50 and calculate their sum.
  5. Write a program to calculate the factorial values between 2 and 7.
  6. Write a program to sort an array of 10 integers in ascending and descending order.
  7. Write a menu-driven program to perform 2x2 Matrix Subtraction and Transpose.

Join Practical C Programming Batch at KKCC Ongole

Get personalized 1-on-1 lab guidance, problem-solving techniques, and live project certification.

Enroll in Ongole Campus