0% found this document useful (0 votes)
9 views11 pages

Crash Preparation Bootcamp

The document outlines a comprehensive cheat sheet tutorial for Computer Science XII, focusing on C programming concepts structured lecture-wise for quick review. Key topics include the history of C, program structure, variables, data types, operators, control structures, functions, and arrays. This tutorial is designed for crash preparation, emphasizing essential concepts and syntax relevant to the syllabus.

Uploaded by

anipak.1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Crash Preparation Bootcamp

The document outlines a comprehensive cheat sheet tutorial for Computer Science XII, focusing on C programming concepts structured lecture-wise for quick review. Key topics include the history of C, program structure, variables, data types, operators, control structures, functions, and arrays. This tutorial is designed for crash preparation, emphasizing essential concepts and syntax relevant to the syllabus.

Uploaded by

anipak.1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Okay, let's create a lecture-wise, comprehensive cheat sheet tutorial for Computer Science XII

(based on Annexure-B6) designed for a crash preparation bootcamp! This will be structured as
a series of "lectures" covering the key topics, focusing on essential concepts and syntax for
quick review.

Computer Science XII - Crash Prep Bootcamp Cheat Sheet Tutorial

Introduction:

Welcome to the Computer Science XII Crash Prep Bootcamp! This cheat sheet tutorial is
designed to rapidly review the core concepts of C programming as outlined in your syllabus
(Annexure-B6). We'll break down the topics lecture-wise to make it digestible and
exam-focused. Let's get started!

Lecture 1: Introduction and History of C Language

●​ What is C?
○​ A powerful, general-purpose programming language.
○​ Known for its efficiency, flexibility, and portability.
○​ Forms the foundation for many other languages.
●​ History (Key Milestones - Very Brief)
○​ Developed at Bell Labs in the early 1970s by Dennis Ritchie.
○​ Evolved from languages like B and BCPL.
○​ Standardized by ANSI (ANSI C or C89) and later ISO (C99, C11, etc.).
●​ Why C is Important:
○​ System programming (operating systems, embedded systems).
○​ Application development.
○​ Foundation for understanding computer architecture and programming principles.

Lecture 2: Basic Structure/Block Structure of a C Program

Anatomy of a C Program:​
// Preprocessor Directives (Lecture 2.1)
#include <stdio.h> // Standard input/output library

// main() function (Lecture 2.2)


int main() {
// Opening brace { (Lecture 2.3 - Delimiter Start)

// Declarations and Statements (Code goes here)


printf("Hello, Bootcamp!\n");
return 0;

// Closing brace } (Lecture 2.3 - Delimiter End)


} ​

●​ Lecture 2.1: Preprocessor Directives (#include)


○​ Start with # symbol.
○​ Instructions to the preprocessor (before compilation).
○​ #include <header_file.h>: Includes header files containing function declarations
and macros (e.g., stdio.h for input/output functions like printf, scanf).
●​ Lecture 2.2: main() Function
○​ The entry point of every C program. Execution begins here.
○​ int main(): Indicates the main function returns an integer value (typically 0 for
successful execution).
○​ (): Parentheses indicate it's a function.
○​ {}: Curly braces enclose the function's body (code block).
●​ Lecture 2.3: Opening and Ending Delimiters (Braces {})
○​ {: Opening brace - Marks the beginning of a code block (function body, loop body,
etc.).
○​ }: Closing brace - Marks the end of a code block.
○​ Importance: Braces define the scope and structure of your code. Mismatched
braces are a common error!

Lecture 3: Variables, Identifiers, Tokens, Constants

●​ Lecture 3.1: Variables


○​ Named storage locations in memory used to hold data.

Declaration: Must be declared before use, specifying data type and name.​
int age; // Declare an integer variable named 'age'
float price; // Declare a float variable named 'price'
char initial; // Declare a character variable named 'initial'

○​ ​

Initialization: Assigning a value to a variable at the time of declaration or later.​


int count = 0; // Declaration and initialization
age = 25; // Initialization after declaration

○​ ​

●​ Lecture 3.2: Identifiers


○​ Names given to variables, functions, labels, etc.
○​ Rules for Identifiers:
■​ Can contain letters (a-z, A-Z), digits (0-9), and underscores (_).
■​ Must start with a letter or underscore.
■​ Cannot start with a digit.
■​ Case-sensitive (age and Age are different).
■​ Cannot be reserved keywords (e.g., int, float, if, for).
●​ Lecture 3.3: Tokens
○​ Smallest individual units in a program. C tokens include:
■​ Keywords: Reserved words with special meaning (e.g., int, float, while,
return).
■​ Identifiers: User-defined names (variables, functions, etc.).
■​ Constants: Fixed values (e.g., 10, 3.14, 'A', "Hello").
■​ Operators: Symbols that perform operations (e.g., +, -, =, ==).
■​ Special Symbols: Punctuation marks (e.g., ;, ,, {}, ()).
●​ Lecture 3.4: Constants
○​ Fixed values that do not change during program execution.
○​ Types of Constants:
■​ Integer Constants: Whole numbers (e.g., 10, -5, 0).
■​ Floating-Point Constants: Numbers with decimal points (e.g., 3.14, -2.5,
0.0).
■​ Character Constants: Single characters enclosed in single quotes (e.g.,
'A', '9', ' ' - space).
■​ String Constants: Sequences of characters enclosed in double quotes
(e.g., "Hello", "123").

Lecture 4: Data Types with Sizes

●​ Fundamental Data Types (Primary Data Types):

Data Type Keyword Size (Bytes - Format Specifier Range


Typical) (for printf, scanf) (Approximate)
Integer int 4 %d -2 billion to +2
billion

Character char 1 %c -128 to +127


(ASCII
characters)

Floating-point float 4 %f ~6 decimal digits


precision

Double float double 8 %lf ~15 decimal


digits precision

Void void 0 (conceptually) N/A (used for Represents


functions with no absence of data
return) type

●​ ​
Size Modifiers:
○​ short: Reduces the size of int (e.g., short int).
○​ long: Increases the size of int or double (e.g., long int, long double).
○​ signed: Allows both positive and negative values (default for int and char).
○​ unsigned: Allows only non-negative values (e.g., unsigned int).

Lecture 5: Operators and Their Usages

●​ Categories of Operators:
○​ Lecture 5.1: Arithmetic Operators:
■​ + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulo -
remainder of integer division)

Example:​
int sum = 10 + 5;
int diff = 10 - 5;
int prod = 10 * 5;
float div = 10.0 / 5.0;
int rem = 10 % 3; // rem will be 1

■​ ​

○​ Lecture 5.2: Relational Operators:


■​ == (Equal to), != (Not equal to), > (Greater than), < (Less than), >=
(Greater than or equal to), <= (Less than or equal to)
■​ Result: Boolean (true or false), represented as 1 (true) or 0 (false) in C.

Example:​
int a = 10, b = 5;
int isEqual = (a == b); // isEqual will be 0 (false)
int isGreater = (a > b); // isGreater will be 1 (true)

■​ ​

○​ Lecture 5.3: Logical Operators:


■​ && (Logical AND), || (Logical OR), ! (Logical NOT)
■​ Operands: Boolean values (or expressions that evaluate to boolean).

Example:​
int x = 5, y = 2;
int resultAND = (x > 0) && (y < 5); // true AND true = true (1)
int resultOR = (x < 0) || (y > 1); // false OR true = true (1)
int resultNOT = !(x == 0); // NOT false = true (1)

■​ ​

○​ Lecture 5.4: Assignment Operators:


■​ = (Simple assignment), +=, -=, *=, /=, %= (Compound assignment)

Example:​
int num = 10; // Simple assignment
num += 5; // num = num + 5; (num becomes 15)
num -= 2; // num = num - 2; (num becomes 13)

■​ ​

○​ Lecture 5.5: Increment and Decrement Operators:


■​ ++ (Increment), -- (Decrement)
■​ Prefix (++i, --i): Increment/decrement before using the value.
■​ Postfix (i++, i--): Increment/decrement after using the value.

Example:​
int count = 5;
int prefixInc = ++count; // count is now 6, prefixInc is 6
int postfixInc = count++; // postfixInc is 6, count is now 7

■​ ​

○​ Lecture 5.6: Conditional Operator (Ternary Operator):


■​ condition ? expression_if_true : expression_if_false
■​ Shorthand for if-else in simple cases.

Example:​
int age = 20;
char *status = (age >= 18) ? "Adult" : "Minor"; // status will be "Adult"

■​ ​

○​ Lecture 5.7: Bitwise Operators (Less Common in Basic XII Syllabus, but
mentioned for completeness):
■​ & (Bitwise AND), | (Bitwise OR), ^ (Bitwise XOR), ~ (Bitwise NOT), <<
(Left shift), >> (Right shift)
■​ Operate on individual bits of integers.
○​ Lecture 5.8: Special Operators:
■​ sizeof(): Returns the size (in bytes) of a variable or data type.
■​ & (Address-of operator): Returns the memory address of a variable (used
with pointers).
■​ * (Dereference operator): Accesses the value at a memory address (used
with pointers).
■​ , (Comma operator): Evaluates expressions from left to right, returns the
value of the rightmost expression.
■​ . (Member access operator): Accesses members of structures and
unions.
■​ -> (Pointer member access operator): Accesses members of structures
and unions through pointers.

Lecture 6: Control Structures


●​ Lecture 6.1: Selection/Decision Making Structures

if statement: Executes a block of code if a condition is true.​


if (condition) {
// Code to execute if condition is true
}

○​ ​

if-else statement: Executes one block of code if a condition is true, and another block if false.​
if (condition) {
// Code if true
} else {
// Code if false
}

○​ ​

else-if ladder: Chain multiple conditions.​


if (condition1) {
// Code for condition1
} else if (condition2) {
// Code for condition2
} else if (condition3) {
// Code for condition3
} else {
// Default code if none of the above conditions are true
}

○​ ​

switch-case statement: Efficiently handles multiple choices based on the value of a variable
(typically integer or char).​
switch (expression) {
case value1:
// Code for value1
break; // Important: Exit switch after case
case value2:
// Code for value2
break;
// ... more cases
default: // Optional default case
// Code if expression doesn't match any case
break;
}

○​ ​

●​ Lecture 6.2: Iterative Structures (Loops)

for loop: Used when you know the number of iterations in advance or need precise control over
initialization, condition, and increment/decrement.​
for (initialization; condition; increment/decrement) {
// Code to be repeated
}

○​ ​

Example: Print numbers 1 to 5:​


for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}

■​ ​

○​

while loop: Repeats a block of code as long as a condition is true. Condition is checked before
each iteration.​
while (condition) {
// Code to be repeated as long as condition is true
// Make sure to update something in the loop to eventually make condition false!
}

○​ ​

Example: Count down from 5 to 1:​


int count = 5;
while (count >= 1) {
printf("%d ", count);
count--;
}

■​ ​

○​

do-while loop: Similar to while, but condition is checked after each iteration. Guarantees at
least one execution of the loop body.​
do {
// Code to be repeated at least once
// Condition is checked at the end
} while (condition);

○​ ​

Example: Get input until a positive number is entered:​


int num;
do {
printf("Enter a positive number: ");
scanf("%d", &num);
} while (num <= 0);
printf("You entered: %d\n", num);

■​ ​

○​
●​ Lecture 6.3: Unconditional Control Statements

goto statement: Jumps to a labeled statement. Generally discouraged in structured


programming as it can make code harder to read and maintain.​
// ...
goto myLabel; // Jump to myLabel:
// ...
myLabel:
// Code at the label ​

○​ break statement: Exits a loop (for, while, do-while) or switch statement


immediately.
○​ continue statement: Skips the current iteration of a loop and goes to the next
iteration.
○​ return statement: Exits a function and optionally returns a value.

Lecture 7: Functions

●​ Lecture 7.1: System-defined/Predefined Functions


○​ Functions provided by the C standard library (header files like stdio.h, math.h,
string.h, etc.).
○​ Examples:
1.​ printf(): Formatted output (from stdio.h).
2.​ scanf(): Formatted input (from stdio.h).
3.​ sqrt(): Square root (from math.h).
4.​ strlen(): String length (from string.h).
○​ How to use: #include the relevant header file and call the function by its name.
●​ Lecture 7.2: User-defined Functions
○​ Functions created by the programmer to perform specific tasks.

Function Declaration (Prototype): Tells the compiler about the function's name, return type,
and parameters before it's used. (Usually placed before main() or in a header file).​
return_type function_name(parameter_list); // Declaration ends with semicolon ;

○​ ​

1.​ return_type: Data type of the value the function returns (e.g., int, float,
void if it returns nothing).
2.​ function_name: Identifier for the function.
3.​ parameter_list: Comma-separated list of parameter declarations (data
type and parameter name). Can be empty () if no parameters.

Function Definition: Provides the actual code (body) of the function.​


return_type function_name(parameter_list) {
// Function body - code to perform the task
// ...
return return_value; // Optional: if return_type is not void
}

○​ ​

Function Calling: To execute a function, you need to "call" it from another part of the program
(e.g., from main() or another function).​
function_name(argument_list); // Calling the function
○​ ​

1.​ argument_list: Comma-separated list of values (arguments) passed to the


function's parameters.
○​ Four Methods of User-Defined Functions (Based on Parameters and Return
Value):
1.​ No arguments and No return value: void myFunction(void)
2.​ Arguments but No return value: void myFunction(int arg1, float arg2)
3.​ No arguments but Return value: int myFunction(void)
4.​ Arguments and Return value: float myFunction(int arg1, char arg2)

Lecture 8: Arrays and Strings

●​ Lecture 8.1: Arrays


○​ Collection of elements of the same data type stored in contiguous memory
locations.

Array Declaration (1D Array):​


data_type array_name[array_size];

○​ ​

■​ data_type: Type of elements in the array (e.g., int, float, char).


■​ array_name: Identifier for the array.
■​ array_size: Number of elements the array can hold (must be a constant
integer).

Array Initialization (1D Array):​


int numbers[5] = {10, 20, 30, 40, 50}; // Initialize at declaration
int grades[3];
grades[0] = 85; // Initialize element by element
grades[1] = 92;
grades[2] = 78;

○​ ​

Accessing Array Elements: Using index (starting from 0).​


int firstElement = numbers[0]; // Access the first element (value 10)
numbers[2] = 35; // Modify the 3rd element (index 2)

○​ ​

Array Declaration (2D Array - Matrix):​


data_type array_name[row_size][column_size];

○​ ​

■​ row_size: Number of rows.


■​ column_size: Number of columns.

Array Initialization (2D Array):​


int matrix[2][3] = { {1, 2, 3}, {4, 5, 6} };
○​ ​

Accessing 2D Array Elements:​


int element = matrix[1][2]; // Access element at row 1, column 2 (value 6)

○​ ​

●​ Lecture 8.2: Strings


○​ In C, strings are treated as character arrays terminated by a null character \0.

Character Array Declaration for Strings:​


char message[50]; // Character array to hold a string of up to 49 characters + null terminator

○​ ​

String Initialization:​
char greeting[] = "Hello"; // Compiler automatically adds null terminator
char name[20] = {'J', 'o', 'h', 'n', '\0'}; // Explicit null termination

○​ ​

○​ Input/Output of Strings:
■​ scanf("%s", string_variable); - Reads a string until whitespace (not safe
for buffer overflow if input is longer than array size).
■​ gets(string_variable); - Reads a whole line of input (until newline
character). Deprecated and unsafe due to buffer overflow risks. Avoid
using gets().
■​ fgets(string_variable, size, stdin); - Safer alternative to gets(). Reads up
to size-1 characters or until newline.
■​ printf("%s", string_variable); - Prints a string.
■​ puts(string_variable); - Prints a string followed by a newline.
○​ String Functions (from string.h header file):
■​ #include <string.h> (Must include this header file)
■​ strlen(string): Returns the length of a string (excluding null terminator).
■​ strcpy(destination_string, source_string): Copies source_string to
destination_string. Make sure destination_string is large enough!
■​ strcmp(string1, string2): Compares string1 and string2. Returns 0 if equal,
negative if string1 < string2, positive if string1 > string2.
■​ strcat(destination_string, string_to_append): Appends string_to_append
to the end of destination_string. Again, ensure destination_string is
large enough!

Lecture 9: Pointers

●​ Lecture 9.1: What are Pointers?


○​ Variables that store the memory address of another variable.
○​ Think of it like a street address that tells you where someone lives.

Lecture 9.2: Pointer Declaration:​


data_type *pointer_name;

●​ ​

○​ data_type: Data type of the variable the pointer will point to.
○​ *: Asterisk indicates it's a pointer variable.
○​ pointer_name: Identifier for the pointer.
●​ Lecture 9.3: Pointer Initialization:

Initialization with Address-of Operator (&): Get the address of an existing variable.​
int num = 25;
int *ptr = # // ptr now stores the memory address of num

○​ ​

Initialization to NULL: Indicate that the pointer doesn't point to any valid memory location
initially.​
int *ptr = NULL; // ptr is a null pointer

○​ ​

●​ Lecture 9.4: Dereference Operator (*)

Used to access the value stored at the memory address pointed to by a pointer.​
int value = *ptr; // value will now be 25 (the value of num)
*ptr = 30; // Modifies the value of num through the pointer (num is now 30)

○​ ​

Lecture 9.5: Pointer Example:​


#include <stdio.h>

int main() {
int number = 100;
int *ptrNumber; // Declare a pointer to an integer

ptrNumber = &number; // Initialize pointer to point to the address of 'number'

printf("Value of number: %d\n", number); // Output: 100


printf("Address of number: %p\n", &number); // Output: Memory address of 'number'
printf("Value of ptrNumber: %p\n", ptrNumber); // Output: Same memory address as above
printf("Value pointed to by ptrNumber: %d\n", *ptrNumber); // Output: 100 (dereferencing)

*ptrNumber = 200; // Change the value of 'number' through the pointer

printf("Value of number after changing through pointer: %d\n", number); // Output: 200

return 0;
}

●​ ​

Conclusion:

This cheat sheet tutorial provides a rapid overview of the essential C programming concepts for
your Computer Science XII exam. Remember to practice coding examples and review past
papers. Focus on understanding the syntax and purpose of each topic. Good luck with your
bootcamp and exams!
Key Takeaways for Exam Preparation:

●​ Syntax is crucial: Pay close attention to the correct syntax for declarations, operators,
control structures, functions, arrays, and pointers.
●​ Understand the purpose of each concept: Don't just memorize syntax; understand
why and when to use each feature.
●​ Practice, practice, practice: Write small programs to solidify your understanding of
each lecture's topics.
●​ Review past papers: Get familiar with the types of questions asked in exams.

This cheat sheet should be a valuable tool for your crash preparation. All the best!

You might also like