0% found this document useful (0 votes)
9 views4 pages

DSA Lab Assignments Svnit Part 1

It is incredible infinite source of knowledge

Uploaded by

Harshit
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)
9 views4 pages

DSA Lab Assignments Svnit Part 1

It is incredible infinite source of knowledge

Uploaded by

Harshit
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

DSA Lab assignment 1

U23CS044
Divyansh Martolia
Study of primitive datatype
Code:
#include <stdio.h>

struct Str {
int i;
float f;
char c;
};

union Un {
int i;
float f;
char c;
};

int main() {
int i;
float f;
char c;

int a1[5];
int a2[3][3];

struct Str s;
union Un u;

int* p = (int*)malloc(5 * sizeof(int));

printf("Address of int: %u , %x\n", &i, &i);


printf("Address of float: %u, %x\n", &f, &f);
printf("Address of char: %u, %x\n", &c, &c);

printf("Address of 1D array: %u, %x\n", &a1, &a1);

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


printf("Address of element %d in 1d array: %u, %x\n", i, &a1[i],
&a1[i]);
}

printf("Address of struct: %u, %x\n", &s, &s);


printf("Address of union: %u, %x\n", &u, &u);

printf("Address of int in struct: %u, %x\n", &s.i, &s.i);


printf("Address of float in struct: %u, %x\n", &s.f, &s.f);
printf("Address of char in struct: %u, %x\n", &s.c, &s.c);

printf("Address of int in union: %u, %x\n", &u.i, &u.i);


printf("Address of float in union: %u, %x\n", &u.f, &u.f);
printf("Address of char in union: %u, %x\n", &u.c, &u.c);

printf("Address of dynamic array: %u, %x\n", &p, &p);

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


printf("Address of element %d in dynamic array: %u, %x\n", i, (p +
i), (p + i));
}

printf("2d int array a\n");

int arry[3][3]={{1,2,3},{4,5,6},{7,8,9}};
printf("Address of 2D array: %u, %x\n", &arry, &arry);
printf("a:%u\n",arry);
printf("*a:%u\n",*arry);
printf("**a:%d\n",**arry);
for(i=0;i<3;i++){
printf("a[%d]:%u\n ",i,arry[i]);
for(int j=0;j<3;j++){
printf("a[%d][%d]:%d ",i,j,arry[i][j]);
printf("&a[%d][%d]:%u\n",i,j,&arry[i][j]);
}
}

free(p);

return 0;
}
Output:

You might also like