A10presentationofbiologyandpshyology.pptx

ranjangamer007 6 views 9 slides May 05, 2024
Slide 1
Slide 1 of 9
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9

About This Presentation

A10 ppt


Slide Content

Lab Assignment 10:

#include < stdio.h > struct College { char college_name [20]; int ranking; struct Student { int student_id ; char name[20]; int roll_no ; } student1; }; int main() { struct College c1 = {" Brainware University", 7,{111, " Amit ", 278}}; printf ("College name : %s\n",c1.college_name); printf ("Ranking : %d\n",c1.ranking); printf ("Student id : %d\n",c1.student1.student_id); printf ("Student name : %s\n",c1.student1.name); printf ("Roll no : %d\n",c1.student1.roll_no); return 0; } Output: College name : Brainware University Ranking : 7 Student id : 111 Student name : Amit Roll no : 278 Write a program to display college information and student information using nested structure.

#include<stdio.h> struct student { char name[20]; int rollno ; int marks; }; void display(char name[],int rollno,int marks); int main() { struct student stu1={"John",12,87}; struct student stu2={"Mary",18,90}; display(stu1.name,stu1.rollno,stu1.marks); printf ("\n"); display(stu2.name,stu2.rollno,stu2.marks); return 0; } void display(char name[],int rollno,int marks) { printf ("Name - %s\ t",name ); printf (" Rollno - %d\t", rollno ); printf ("Marks - %d\ t",marks ); } Output : Name - John Rollno - 12 Marks - 87 Name - Mary Rollno - 18 Marks - 90 Program to pass Structure members as Arguments:

#include<stdio.h> struct student { char name[20]; int rollno ; int marks; }; void display(struct student); int main() { struct student stu1={"John",12,87}; struct student stu2={"Mary",18,90}; display(stu1); printf ("\n"); display(stu2); return 0; } void display(struct student stu ) { printf ("Name - %s\ t",stu.name ); printf (" Rollno - %d\t", stu.rollno ); printf ("Marks - %d\t", stu.marks ); } Output: Name - John Rollno - 12 Marks - 87 Name - Mary Rollno - 18 Marks - 90 Program to pass Structure Variable as Argument:

#include < stdio.h > #include<string.h> int main() { char dest [50] = "This is an"; char src [50] = " example"; printf (" dest Before: %s\n", dest ); // concatenating src at the end of dest strcat ( dest , src ); printf (" dest After: %s", dest ); return 0; } C Program to understand the strcat function Output: dest Before: This is an dest After: This is an example

#include<stdio.h> int main ( ) { int a = 87; int *p1 = &a; printf ("Value of p1 = Address of a = %p\n", p1); printf ("Address of p1 = %p\n", &p1); printf ("Value of a = %d %d %d\n", a, *p1, *(&a)); return 0; } Output: Value of p1 = Address of a = 0012FED Address of p1 = 0012FEBC Value of a = 87 87 87 Program to understand dereferencing pointer variables:

#include<stdio.h> int main ( ) { int a=5,*pi=&a; char b='x',*pc=&b; float c=5.5,*pf=&c; printf ("Value of pi=Address of a=%p\ n",pi ); printf ("Value of pc=Address of b=%p\ n",pc ); printf ("Value of pf=Address of c=%p\ n",pf ); pi++; pc++; pf++; printf ("Now value of pi=%p\ n",pi ); printf ("Now value of pc=%p\ n",pc ); printf ("Now value of pf=%p\ n",pf ); return 0; } Output: Value of pi=Address of a=0x7fffba31e274 Value of pc=Address of b=0x7fffba31e273 Value of pf=Address of c=0x7fffba31e26c Now value of pi=0x7fffba31e278 Now value of pc=0x7fffba31e274 Now value of pf=0x7fffba31e270 Program to understand pointer arithmetic:

#include<stdio.h> int main ( ) { int a=5; int *pa; int ** ppa ; pa=&a; ppa =&pa; printf ("Address of a=%p\ n",&a ); printf ("Value of pa=Address of a=%p\ n",pa ); printf ("Value of *pa=Value of a=%d\n",*pa); printf ("Address of pa=%p\ n",&pa ); printf ("Value of ppa =Address of pa=%p\n", ppa ); printf ("Value of * ppa =Value of pa=%p\n",* ppa ); printf ("Value of ** ppa =Value of a=%d\n",** ppa ); printf ("Address of ppa =%p\n",& ppa ); } Program to understand pointer to pointer variable: Output: Address of a=0x7ffff40ead9c Value of pa=Address of a=0x7ffff40ead9c Value of *pa=Value of a=5 Address of pa=0x7ffff40ead90 Value of ppa =Address of pa=0x7ffff40ead90 Value of * ppa =Value of pa=0x7ffff40ead9c Value of ** ppa =Value of a=5 Address of ppa =0x7ffff40ead88

#include<stdio.h> void swap( int,int ); int main() { int a,b,r ; printf ("enter value for a & b: "); scanf ("% d%d ",& a,&b ); swap( a,b ); return 0; } void swap(int a,int b) { int temp; temp=a; a=b; b=temp; printf ("after swapping the value for a & b is : %d %d", a,b ); } Output: enter value for a & b: 23 12 after swapping the value for a & b is : 12 23 Write a C program to perform swapping using function.