[go: up one dir, main page]

0% found this document useful (0 votes)
15 views8 pages

DS PROGRAMSWITHSOLUTIONfirst5

The document contains several C programs demonstrating pointer operations, call-by-value, call-by-reference, and structure usage. It includes examples of pointer increment/decrement, addition/subtraction, and functions to swap values using different methods. Additionally, it showcases how to create and manage student records using structures in C.
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)
15 views8 pages

DS PROGRAMSWITHSOLUTIONfirst5

The document contains several C programs demonstrating pointer operations, call-by-value, call-by-reference, and structure usage. It includes examples of pointer increment/decrement, addition/subtraction, and functions to swap values using different methods. Additionally, it showcases how to create and manage student records using structures in C.
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
You are on page 1/ 8

7. W.a.p. for pointer increment/Decrement operation.

#include <stdio.h>

#include <conio.h>

void main()

int a=10;

int *ptr;

clrscr();

ptr=&a;

printf("Address before increment/decrement operation : %p\n",ptr);

ptr++;

printf("Address after increment : %p\n",ptr);

ptr--;

printf("Address after decrement : %p\n",ptr);

getch();

OUTPUT :

Address before increment/decrement operation : 1001

Address after increment : 1005

Address after decrement : 1001


8. W.a.p. for pointer addition/subtraction operation.

#include<stdio.h>

#include<conio.h>

void main()

int num=10;

int *ptr;

clrscr();

ptr=&num;

printf("Address before addition/subtraction operation : %p\n",ptr);

ptr=ptr+3;

printf("Address after addition : %p",ptr);

ptr=ptr-3;

printf("Address after subtraction : %p",ptr);

getch();

Output :

Address before addition/subtraction operation : 1000

Address after addition : 1012

Address after subtraction : 1000


9. W.a.p. to demonstrate the call-by-value in udf.

#include <stdio.h>

#include<conio.h>

void swap(int x , int y);

void main()

int x, y;

printf("Enter the value of x and y\n");

scanf("%d%d",&x,&y);

printf("Before Swapping\nx = %d\ny = %d\n", x, y);

swap(x, y);

printf("After Swapping\nx = %d\ny = %d\n", x, y);

getch();

void swap(int x, int y)

int temp;

temp = y;

y = x;

x = temp;

printf(“After calling function\nvalue of X= %d\n”,x);

printf(“value of Y= %d\n”,y);

Output:
Enter the value of x and y
Before Swapping
x = 10
y=5
After calling function
X=5
Y=10
After Swapping
x = 10
y=5

10. W.a.p. to demonstrate the call-by-reference in udf.

#include <stdio.h>

#include <conio.h>

void swap(int*, int*);

void main()

int x, y;

printf("Enter the value of x and y\n");

scanf("%d%d",&x,&y);

printf("Before Swapping\nx = %d\ny = %d\n", x, y);

swap(&x, &y);

printf("After Swapping\nx = %d\ny = %d\n", x, y);

return 0;

void swap(int *a, int *b)


{

int temp;

temp = *b;

*b = *a;

*a = temp;

Output:

Enter value of x and y


10
20
Before Swapping
x = 10
y = 20
After Swapping
X=20
Y=10

11. W.a.p c program which have one structure including rollno, age and student name as their
members , take user input to store one student’s record and print the same data.

#include<stdio.h>

#include<conio.h>

struct student {

int roll_no,age;

char name[25];

}s1;

int main()

printf("enter roll no\n ");


scanf("%d",&s1.roll_no);

printf("enter student name \n");

scanf("%s",s1.name);

printf("enter student age\n");

scanf("%d",&s1.age);

printf("student roll no %d\n",s1.roll_no);

printf("student name is %s\n",s1.name);

printf("student age %d\n",s1.age);

return 0;

Output :

enter roll no :1
enter student name : ABC
enter student age : 20
student roll no 1
student name is ABC
student age 20
12. W.a.p. which includes stud structure and make five objects for that structure and print their
data.

#include <stdio.h>

struct student {

char firstName[50];

int roll,age;

} s[10];

int main() {

int i;

printf("Enter information of students:\n");

// storing information

for (i = 0; i < 5; i++) {

printf("\nFor roll number\n);

scanf("%d",&s[i].roll);

printf("Enter first name: ");

scanf("%s", s[i].firstName);

printf("Enter age: ");

scanf("%d", &s[i].age);

printf("Displaying Information:\n\n");

// displaying information

for (i = 0; i < 5; i++) {

printf("student roll no %d\n",s[i].roll);

printf("student name is %s\n",s[i].firstName);

printf("student age %d\n",s[i].age);

return 0;

Output:
Enter information of students:

For roll number1,

Enter name: Tom

Enter age : 25

….

Displaying Information:

Student Roll number: 1

Student Name is : Tom

Student age : 25

You might also like