C notes
C notes
a)
Definition:-
struct structure_name
{
data_type member1;
data_type member2;
// Other members...
}structure variable;
Where:
b)
A character array is simply an array of characters. It is used to store a sequence of characters in
a contiguous block of memory.
To declare a character array in C, you specify the type char, followed by the name of the array
and the number of elements
For example:
char name[10];
Syntax
Need of fuction
Functions allow for the modularization of code, making it more organized, reusable, and easier to
debug.
e)
malloc(): Allocates a specified number of bytes of memory and returns a pointer to the first
byte, initializing the memory to garbage values.
calloc(): Allocates memory for a specified number of elements, each of a specified size, and
initializes all the bytes to zero.
getchar(): Reads a single character from the standard input (keyboard) and returns it as an
integer.
Pointer Declaration:
data_type *pointer_name;
For example:
Pointer Initialization:
To initialize a pointer, you assign it the address of a variable using the address-of operator (&).
int a = 10;
int *ptr = &a; // Initializes ptr to the address of variable a
Here:
a is an integer variable.
ptr is a pointer that holds the memory address of a.
&a is the address of a.
Simple Example:
#include <stdio.h>
void main()
int num = 5;
int *ptr;
ptr = #
getch();
}
g)
1. & (Address-of operator):
The & operator is used to obtain the memory address of a variable. It returns the address where a
variable is stored.
Syntax
&variable_name
int a = 10;
int *ptr;
ptr = &a; // &a gives the address of 'a' and stores it in ptr
2. * (Dereference operator):
The * operator is used to access the value stored at the memory address a pointer is pointing to. It
is called dereferencing the pointer.
Syntax
*pointer_name
If ptr is a pointer to an integer, *ptr gives the value stored at the memory address pointed to by
ptr.
Q.2
a)
#include<stdio.h>
#include<conio.h>
void main()
int a[10],i;
clrscr();
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=0;i<10;i++)
printf("\n %d ",a[i]);
getch();
}
b)
c)
Here is a list of string handling functions in C:
1. strlen()
2. strcpy()
3. strcat()
4. strcmp()
5. strlwr()
6. struppr()
7. strrev()
strlen():- It is a standard predefined string handling function used to find length of a string
Syntax :- strlen(str)
Syntax :- strrev(str)
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
char str[30];
clrscr();
scanf(“%s”,&str);
e)
#include<stdio.h>
#include<conio.h>
void product();
void main()
int a,b;
clrscr();
getch();
f)
#include<stdio.h>
#include<conio.h>
void main()
int a=10,*ptr;
clrscr();
ptr=&a;
getch();