POP3rd Internals
POP3rd Internals
F.No:DrTTIT/IQAC/2022-23/059AP
CO Description
CO4 Explore user defined data structures like strings and pointers.
CO5 Design and develop solutions to problems using structures, union, and FILE I/O operations
F.No:DrTTIT/IQAC/2022-23/059BP
Part-A
Declaration
General form:
data_type*pointer_name 2
● * tells thar variable pointer_name is a pointer variable.
● Pointer_name is a identifier
Ex: int*ptr;
2
Initialization
● Declare a data variable
● Assign address of data to pointer variable using & operator and assignment
operator
Ex: int x;
int*p
p=&x;
1b.
Program
#include<stdio.h>
#include<conio.h>
#include<math.h>
printf("Standard deviation=
%.3f\t", std);
}
2a.. String 1
Declaration
2
It is defined like an array of character
Initialization
2
Syntax: data_type string name[size]=value;
2b. Program
#include <stdio.h>
*a = *b;
*b = temp;
int main()
int x = 5, y = 10;
swap(&x, &y);
return 0;
}
Part-B
3 (i). strcat() 5
It is used to concatenate or join two strings together
Syntax: strcat(destination,source);
Example:
char first[30]=”Computer”;
Strcat(first,last);
(ii). strcmp()
It is used to compare 2 strings. It takes strings as a parameters and returns an
integer value
Syntax: result=strcmp(first,second);
Result=0 🡪first=second
Result>0🡪 first>second 5
Result<0🡪 first<second
4) (i)Generic pointer 5
These pointers are used when a pointer has to point to data of different types at different
times
Example:
#include <stdio.h>
int main()
{
int var = 10;
int *ptr = &var;
printf("Value of var: %d\n", var);
printf("Address of var: %p\n", &var);
printf("Value of ptr (address of var): %p\n", ptr);
printf("Value pointed to by ptr: %d\n", *ptr);
return 0;
}
(ii)NULL pointers
A null pointer which is a special pointer value that is known not to point anywhere. It
means it does not point to any valid memory address. 5
To declare a null pointer you may use the predefined constants NULL;
Example:
int*ptr=NULL;
or
if(ptr==NULL)
{
Statement block;
}
Part-C
Structure
Structure is basically a user defined data type that can store related information (even of
different data types) together.
Declaration
struct tagname
{
data_type var-name;
data_type var-name;
……………..
};
Example:
struct student
{
Int r_no;
Char name[20];
5. Char course[20]; 5
Float fees;
};
Initialization
syntax:
struct struct_name;
{
data_type member_name1;
data_type member_name2;
……………………………………….
………………………………………
data_type member_namen;
};
Enumerated data type
Enumerated data type (or enum) is a user-defined data type that consists of a set of
named integer constants.It allows you to define variables that can only take one of a
few predefined values, making your code more readable and maintainable.
syntax
enum enum_name
{
constant1 = value1,
constant2 = value2,
constant3 = value3,
...
};
program
#include <stdio.h>
6 enum day { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; 5
int main()
{
enum day today;
enum variable today = Wednesday;
printf("The value of today is: %d\n", today);
return 0;
}
Course Instructor