CS XII Crash Course
CS XII Crash Course
provided (Annexure-B6). This is designed to be concise and exam-focused, hitting the key
points.
Goal: To quickly revise key concepts and prepare for the Computer Science XII exam based on
the reduced syllabus. Focus on understanding the core ideas and practicing programming.
● Review each section: Read through the explanations and key points for each topic.
● Study the examples: Understand the code examples provided. They are designed to
illustrate the concepts.
● Practice the questions: Attempt the MCQs and short answer/coding questions at the
end of each section. This is crucial for exam preparation.
● Focus on syntax: Pay close attention to the syntax of C programming as it's heavily
emphasized in the syllabus.
● Time Management: Allocate your time effectively to cover all topics. Prioritize topics you
find challenging.
● Don't skip practice! Programming is a skill best learned by doing.
Sections:
● Key Points:
○ History: Briefly know the origins of C (Bell Labs, Dennis Ritchie, based on B,
influenced by ALGOL 60). Understand its purpose (system programming initially).
○ Importance of C: Why is C still relevant? (Foundation for many languages,
system programming, embedded systems, performance).
○ Generations of Programming Languages (Briefly): Machine Language,
Assembly Language, High-Level Languages (C is High-Level).
● Example Question (MCQ):
○ C language was developed at:
a) Microsoft
b) Apple
c) Bell Laboratories (Correct)
d) IBM
● Key Points:
○ Preprocessor Directives: #include <stdio.h>, #include <conio.h>. Purpose of
#include. What are header files? (e.g., stdio.h for standard input/output
functions).
○ main() function: The entry point of every C program. int main(), void main().
Return type of main.
○ Opening and Ending Delimiters (Braces): { and }. Block of code within braces.
○ Source Code: Human-readable instructions written in C.
○ Compilation & Execution (Briefly): Source code -> Compiler -> Object Code ->
Linker -> Executable -> Execution.
● Example Code Structure:
● Key Points:
○ Variables: Named storage locations to hold data. Declaration (e.g., int age;).
Initialization (e.g., int age = 20;). Data types associated with variables.
○ Identifiers: Names given to variables, functions, etc. Rules for identifiers (start
with letter or underscore, can contain letters, digits, underscores, case-sensitive).
○ Tokens: Smallest individual units in a program. Categories of tokens:
■ Keywords: Reserved words (e.g., int, float, if, else, for, while).
■ Identifiers: User-defined names.
■ Constants: Fixed values (e.g., 10, 3.14, "Hello").
■ Operators: Symbols that perform operations (e.g., +, -, *, /, =, ==).
■ Special Symbols: ;, ,, (, ), {, } etc.
○ Constants: Fixed values that don't change during program execution. Types of
constants:
■ Integer Constants: (e.g., 10, -5, 0)
■ Floating-Point Constants (Real Constants): (e.g., 3.14, -2.5, 0.0)
■ Character Constants: Single characters enclosed in single quotes (e.g.,
'A', 'b', '$')
■ String Constants: Sequences of characters enclosed in double quotes
(e.g., "Hello", "Computer Science")
● Example Question (MCQ):
○ Which of the following is a valid identifier in C?
a) 1variable
b) my variable
c) _my_variable (Correct)
d) int
● Key Points:
○ Primary Data Types (Fundamental Data Types):
■ int: Integer (whole numbers). Size (typically 2 or 4 bytes, depends on
compiler).
■ float: Floating-point (single-precision decimal numbers). Size (typically 4
bytes).
■ char: Character (single character). Size (1 byte).
■ double: Double-precision floating-point numbers. Size (typically 8 bytes).
■ void: Represents the absence of data type.
○ Derived Data Types (Briefly): Arrays, pointers, structures, unions (mention, but
focus on primary).
○ Size of Data Types (Approximate): Understand that sizes can vary slightly
based on the compiler and system architecture, but know the typical sizes.
● Example Table (Data Types and Sizes - Typical):
int Integer 2 or 4
float Floating-point 4
char Character 1
●
Practice Question (Short Answer):
○ List the primary data types in C. What is the typical size of an int data type?
● Key Points:
○ Types of Operators:
■ Arithmetic Operators: +, -, *, /, % (modulus - remainder).
■ Relational Operators: == (equal to), != (not equal to), >, <, >=, <=.
Return boolean values (true/false - represented as 1/0 in C).
■ Logical Operators: && (logical AND), || (logical OR), ! (logical NOT).
Operate on boolean expressions.
■ Assignment Operators: = (simple assignment), +=, -=, *=, /=, %=
(compound assignment).
■ Increment/Decrement Operators: ++ (increment), -- (decrement). Prefix
and postfix forms (++i vs i++).
■ Conditional Operator (Ternary Operator): ? : (e.g., condition ?
value_if_true : value_if_false).
■ Bitwise Operators (Mention briefly): &, |, ^, ~, <<, >> (if syllabus depth
requires, otherwise less important for crash course).
● Example Code (Operators):
int a = 10, b = 5;
int sum, diff, prod, quot, rem;
int result;
sum = a + b; // Arithmetic +
diff = a - b; // Arithmetic -
prod = a * b; // Arithmetic *
quot = a / b; // Arithmetic /
rem = a % b; // Arithmetic %
6. Control Structures
● Key Points:
○ Selection/Decision Making Structures:
■ if statement: Basic if block.
■ if-else statement: if block and else block.
■ else-if ladder: Multiple conditions using else if.
■ switch-case statement: Multi-way branching based on the value of an
expression. case, break, default.
○ Iterative Structures (Loops):
■ for loop: Initialization, condition, increment/decrement in the loop header.
■ while loop: Condition checked before each iteration.
■ do-while loop: Condition checked after each iteration (loop executes at
least once).
○ Unconditional Control Statements:
■ goto statement (Avoid if possible, but know it exists): Unconditional
jump to a labeled statement. Generally considered bad practice for
structured programming.
■ return statement: Exits a function and returns a value (if any).
■ break statement: Exits a loop or switch statement prematurely.
■ continue statement: Skips the rest of the current iteration and goes to
the next iteration of a loop.
● Example Code (Control Structures - Snippets):
○ if-else:
●
○ for loop:
●
○ while loop:
int count = 0;
while (count < 3) {
printf("Count: %d\n", count);
count++;
}
●
○ switch-case:
7. Functions
● Key Points:
○ System-defined/Predefined Functions: Functions provided by the C library
(e.g., printf(), scanf(), sqrt(), pow(), strlen(), gets(), puts(), getch(), clrscr()).
Header files associated with them (e.g., stdio.h, math.h, string.h, conio.h).
○ User-defined Functions: Functions created by the programmer to perform
specific tasks.
○ Function Declaration (Prototype): Specifies function name, return type, and
parameters before function definition or main() function. (e.g., int add(int a, int
b);).
○ Function Definition: Actual code block of the function that performs the task.
○ Function Calling: Invoking a function to execute its code.
○ Four Methods of User-defined Functions (Based on parameters and return
values):
1. No parameters, no return value: void myFunction(void)
2. Parameters, no return value: void myFunction(int x)
3. No parameters, return value: int myFunction(void)
4. Parameters, return value: int myFunction(int a, int b) (Most common)
● Example Code (Functions):
#include <stdio.h>
int main() {
int result = add(5, 3); // Function call
printf("Sum: %d\n", result); // Output: Sum: 8
return 0;
}
// Function definition
int add(int num1, int num2) {
int sum = num1 + num2;
return sum; // Return value
}
int marks[5];
printf("Enter marks for 5 students:\n");
for (int i = 0; i < 5; i++) {
scanf("%d", &marks[i]);
}
printf("Marks are:\n");
for (int i = 0; i < 5; i++) {
printf("%d ", marks[i]);
}
printf("\n");
●
○ 2D Array (Matrix):
○ Strings:
char name[20];
printf("Enter your name: ");
gets(name); // Input string (use caution)
printf("Hello, %s!\n", name);
printf("Length of name: %d\n", strlen(name));
●
● Key Points:
○ What are Pointers? Variables that store memory addresses of other variables.
○ Declaration: data_type *pointer_name; (e.g., int *ptr; - pointer to an integer). * is
the dereference operator (when used in declaration, it indicates a pointer).
○ Initialization:
■ Address-of Operator (&): Get the address of a variable (e.g., ptr =
&variable;).
■ Null Pointer: ptr = NULL; (Indicates pointer doesn't point to anything
valid).
○ Dereferencing Operator (*): Access the value at the memory address pointed to
by the pointer (e.g., *ptr gives the value of the variable ptr is pointing to).
○ Pointer Arithmetic (Briefly - if needed for syllabus depth):
Incrementing/decrementing pointers (moves pointer to next/previous memory
location of the data type it points to).
○ Pointers and Arrays (Close Relationship - Array name acts as a pointer to
the first element).
● Example Code (Pointers):
#include <stdio.h>
int main() {
int num = 10;
int *ptr; // Pointer declaration
printf("New value of num: %d\n", num); // Output: New value of num: 25 (num is changed!)
return 0;
}
Exam Tips:
● Practice, Practice, Practice: Code as many programs as you can. Work through
examples, modify them, and try writing programs from scratch.
● Understand Syntax: C is syntax-sensitive. Pay attention to semicolons, braces,
parentheses, etc.
● Trace Code: Practice tracing code execution on paper to understand how programs
work step-by-step.
● Focus on Concepts: Don't just memorize syntax. Understand the why and how of each
concept.
● Review Past Papers (if available): Get an idea of the question patterns and difficulty
level.
● Manage Time in Exam: Plan your time effectively. Don't spend too much time on one
question.
Resources: