C answers
C answers
Short Notes
a) Bitwise Operator
Operators that perform bit-level operations on data. Examples include AND (&), OR (|), XOR (^), NOT
(~), Left Shift (<<), and Right Shift (>>). They are useful for low-level programming, masking bits, and
optimizing performance.
• Structure: A user-defined data type in C that groups variables of different types. Memory is
allocated for all members.
• Union: A user-defined data type where all members share the same memory location, so
only one member holds a value at a time.
c) Pre-Processor
A tool that processes code before compilation. Common preprocessor directives include #define,
#include, #ifdef, and #pragma.
d) Switch Case
A control statement used for decision-making, where a variable’s value is matched against multiple
case labels. If no match is found, the default block is executed.
e) Array of Structure
An array where each element is a structure. Useful for managing collections of records, e.g., student
data.
Allocating memory during runtime using functions like malloc, calloc, realloc, and free. Enables
efficient memory management.
g) Pointer Arithmetic
Manipulating memory addresses using arithmetic operations like addition, subtraction, increment
(++), and decrement (--). Example: accessing array elements via pointers.
h) Pointer to Pointer
A pointer that stores the address of another pointer. Used for dynamic allocation of multi-
dimensional arrays and passing functions by reference.
2. Differences
a) break vs continue
• continue: Skips the current iteration and continues with the next iteration.
b) while vs do-while
• while: Condition is checked before executing the loop body.
• do-while: Loop body is executed at least once before the condition is checked.
c) Recursion vs Iteration
d) Array vs Structure
e) Structure vs Union
• Call by Value: Function receives a copy of the variable. Changes do not affect the original.
• Call by Reference: Function receives the address of the variable. Changes affect the original.
g) malloc vs calloc
3. Theory / Descriptive
Flowchart Example
Storage Classes
Specify the lifetime, scope, and visibility of variables. Types: auto, static, extern, register.
Example:
void example() {
static int count = 0; // retains value across calls
Functions
Allocating memory during runtime using functions like malloc, calloc, realloc. Example:
Definitions
4. Programs
// Iterative
int factorial(int n) {
int fact = 1;
return fact;
// Recursive
int factorialRec(int n) {
if (n <= 1) return 1;
Fibonacci Series
Copy code
void fibonacci(int n) {
int a = 0, b = 1, next;
next = a + b;
a = b;
b = next;
bool isPrime(int n) {
if (n % i == 0) return false;
return true;
Palindrome Check
while (l < h) {
l++, h--;
return true;
Copy code
if (b == 0) return a;
int l = 0, h = strlen(str) - 1;
while (l < h) {
str[l++] = str[h];
str[h--] = temp;
str1++, str2++;
File Reading
char line[256];
if (file == NULL) {
return;
printf("%s", line);
fclose(file);