Chapter 1
C Language Fundamentals & Logic
Understand variables, data types, operators, conditional branches, loops, functions, and pointers.
C Programming: Logic & Foundation
C was developed by Dennis Ritchie in 1972 at Bell Laboratories. It is a procedural, compiled, middle-level programming language that directly interacts with system hardware.
Structure of a C Program:
#include <stdio.h>
int main() {
// Variable declaration
int roll = 101;
float marks = 88.5;
char grade = 'A';
printf("Roll: %d | Marks: %.1f | Grade: %c\n", roll, marks, grade);
return 0;
}
Format Specifiers:
%dor%i: Signed integer%f: Floating point number%c: Single character%s: String (character array)%p: Memory address pointer
Hands-on Laboratory Procedures & Shortcuts
Follow the steps below to practice directly on your computer.
Loops & Logic Program: Fibonacci Series
#include <stdio.h>
int main() {
int n = 10, t1 = 0, t2 = 1, nextTerm;
printf("Fibonacci Series: %d, %d", t1, t2);
for (int i = 3; i <= n; ++i) {
nextTerm = t1 + t2;
printf(", %d", nextTerm);
t1 = t2;
t2 = nextTerm;
}
printf("\n");
return 0;
}
Watch the video class above while following along with the practical exercises.
Key Summary & Revision Bullet Points
Quick cheat-sheet to review before online examinations.
• Entry Point: Execution always starts at
• Pointers: A pointer is a variable that stores the memory address of another variable (e.g.
•
main().• Pointers: A pointer is a variable that stores the memory address of another variable (e.g.
int *ptr = #).•
sizeof() operator returns the size in bytes allocated for a datatype or variable. Frequently Asked Viva & Exam Questions
Review these standard questions frequently asked in diploma exams and job interviews.
Q1: What is a Pointer in C?
Ans: A pointer is a variable that holds the memory address of another variable. The address-of operator
Q2: What is the difference between
Ans:
Ans: A pointer is a variable that holds the memory address of another variable. The address-of operator
& fetches the address, while the dereference operator * accesses the value stored at that address.Q2: What is the difference between
malloc() and calloc()?Ans:
malloc() allocates a single block of uninitialized memory containing garbage values. calloc() allocates multiple blocks and initializes every byte to zero. Interactive Chapter Quiz
Test your mastery immediately! Click an option to see instant answer feedback.
Q1 Who developed the C programming language in 1972?
A. Bjarne Stroustrup
B. Dennis Ritchie
C. James Gosling
D. Guido van Rossum
Explanation: Dennis Ritchie created C at AT&T Bell Labs in 1972.
Q2 Which format specifier is used to print an integer in C?
A. %c
B. %f
C. %d
D. %s
Explanation: %d is the format specifier for signed integers in printf/scanf.
Q3 Which operator is used to obtain the memory address of a variable in C?
A. *
B. &
C. ->
D. #
Explanation: The ampersand (&) is the address-of operator.
Q4 Which function is used to dynamically allocate memory initialized to zero?
A. malloc()
B. calloc()
C. realloc()
D. free()
Explanation: calloc() allocates contiguous memory and clears all bytes to zero.
Q5 What is the correct syntax to terminate every statement in C?
A. Period (.)
B. Colon (:)
C. Semicolon (;)
D. Comma (,)
Explanation: All statements in C must conclude with a semicolon (;).