Pointer
Pointer
0801IP221002
Sec - G
Roll no. AB22G083
LAB ASSIGNMENT 4
1.1 write the program in C to demonstrate the use of &( address of )and *(value at address)
operator .
Source code -
#include <stdio.h>
int main()
{
int x = 10;
int *p;
p = &x;
return 0;
}
Output
Aaditya Bhatnagar
0801IP221002
Sec - G
Roll no. AB22G083
1.2.Write a programme in c to compute the sum of all elements in an array using pointer.
Source code -
#include <stdio.h>
int main()
int *p;
int sum = 0;
p = arr;
sum += *p;
p++;
return 0;
Output-
int main()
Aaditya Bhatnagar
0801IP221002
Sec - G
Roll no. AB22G083
{
int x = 10;
int y = 20;
printf("Before swapping: x = %d, y = %d\n", x, y);
swap(&x, &y);
printf("After swapping: x = %d, y = %d\n", x, y);
return 0;
}
Output-
Source code -
#include <stdio.h>
}
return count;
}
int main()
{
char str[] = "Hello world";
printf("The length of the string '%s' is %d\n", str, length(str));
return 0;
}
Output-
4. Create a structure named students to specify data on students given below roll number,
name, department of course, year of joining and then display record of 10 students by using
array of structure.
Source code-
#include <stdio.h>
struct student
{
int roll_no;
char name[20];
Aaditya Bhatnagar
0801IP221002
Sec - G
Roll no. AB22G083
char dept[10];
char course[10];
int year;
};
int main()
{
struct student s[10];
int i;
return 0;
}
Output-
5. Create a structure to specify data of customers in a bank the data to be stored is account
number, name, balance in account. assume maximum of 20 customers in the bank write a
function to print the account number and name of each customer with balance low of rupees
100.
Aaditya Bhatnagar
0801IP221002
Sec - G
Roll no. AB22G083
Source code -
#include <stdio.h>
struct customer
{
int acc_no;
char name[20];
int balance;
};
}
if (count == 0)
{
printf("No customer has balance below 100.\n");
}
}
int main()
{
struct customer c[20];
int n;
int i;
print_low_balance(c, n);
return 0;
}
Output-
specify data of customers in a bank. The data to be stored is account number, name, balance in