0% found this document useful (0 votes)
29 views4 pages

C Prep

Uploaded by

Sindhuja K
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)
29 views4 pages

C Prep

Uploaded by

Sindhuja K
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

1, Basic pointers

2, Strings - string functions


3, Storage classes
4, Advance pointers - 2D array, Dynamic memory, void * etc
5, UDT
6, Files
7, Misc

What?
How?
Basic pointers
Why?
What is pointer? -> Use? Where?
When?
1, Pass by ref
2, Dynamic memory

Why ? when? pass by ref

1, return more than 1 value - sum_prod, swap values,


2, passing array & string
3, UDT - struct

strings - Array of chars ending with nul

What are limitations of strcpy?

1. No limit checking
2. Won't work without nul

1. WAP to reverse a string. recursive


Eg hello -> olleh
2. WAP to reverse words in string
a) hello world -> world hello
b) hello world -> olleh dlrow
3. WAP to check palindrom
4. Find palindromes in on line.
5. WAP to find occurance of a word in a given string. Eg - of

Storage classes - memory segments

Code :- coverted machine level instruction + constant literals


10, 10.5, 'a', "hello"
Data :- Global & static

Stack :- auto local, fun args, return address

Heap :- Dynamic memory


Local -> auto, register, static (Scope is block)

Global -> Scope is entire program or file


extern * static

for(i=0; i<row; i++)


{
for(j=0; j<col; j++)
2D array
{
arr[i][j];
1. BS both static
}
}
Eg: int arr[3][4];

pointer to 1D array

scan_array(3, 4, arr)

scan_array(int r, int c, int (*arr)[c])

2. FSSD first static second dynamic

Array of pointers

int *arr[3];
for(i = 0; i < 3; i++)
{
arr[i] = malloc(4 * sizeof(int));
}

scan_array(arr, 3, 4)

scan_array(int *arr[], int r, int c)

3. BD both dynamic

Array of pointers

int **arr = malloc(3 * sizeof(int *))


for(i = 0; i < 3; i++)
{
arr[i] = malloc(4 * sizeof(int));
}
scan_array(arr, 3, 4)

scan_array(int *arr[], int r, int c)

4. FDSS first dynamic second static

pointer to 1D array

int (*arr)[5] = malloc(4 * sizeof(int[5]))


scan_array(4, 5, arr)

scan_array(int r, int c, int (*arr)[c])

1. WAP to allocate 2D array using both dynamic, scan and print


2. WAP find largest/smallest 1 2 3
3. WAP to store and print transpose od 2D array. 4 5 6
4. WAP to rotate 2D array in 90 degree clockwise 7 8 9

1 2 3 1 4 7 7 4 1
4 5 6 2 5 8 8 5 2
7 8 9 3 6 9 9 6 3

5. print 2D array in spiral format


1 2 3 4
5 6 7 8
9 10 11 12

void *

Generic pointer used for writing generic functions


Same logic/code for different datatype
Eg: sort(), search(), find_largest(), swap() etc

WAP - swap()

UDT

Structure -> Eg : explain with project


bitfield struct

Union -> To access same memory through different type


Eg: temp senser, ieee_float, access hardware/ports, endianness

PORTB union PORTS


RB0 {
RB1 char PORTB;
struct {
unsigned char RB7:1;
unsigned char RB6:1;
..
}
}

Structure padding

* Wordsize
* Data alignment
* CPU cycle saving
* avoid padding
Files -> ASCII, Binary

read/write char by char - fget/getc, putc/fputc


read/write line by char
1. fgets()
2. fscanf()
read complete/ huge content
1 fread()

volatile (unpredictable) Eg: Delay example

1, What is optimization
2, How to optimize using compler
3, How optimization currupt code. LED on/off with swtich
4, How volatile helps to overcome.
volatile const SW = 0; // off
LED = 0;// off

while(1)
{
if(SW == 1)
LED = 1;
else
LED = 0;
}

You might also like