Lab 11

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Q1) #include <stdio.

h>

int main() {

long value1 =

200000; long

value2;

long *lPtr;

lPtr = Cvalue1;

printf("Value pointed to by lPtr: %ld\n",

*lPtr); value2 = *lPtr;

printf("Value of value2: %ld\n", value2);

printf("Address of value1: %p\n",

(void*)Cvalue1); printf("Address stored in

lPtr: %p\n", (void*)lPtr); if (lPtr ==

Cvalue1) {

printf("The address in lPtr is the same as the address of value1.\n");

} else {

printf("The address in lPtr is different from the address of value1.\n");

Q2) #include <stdio.h>

void swapped(int *aptr, int *bptr, int

*cptr) { int temp = *bptr;

*bptr = *aptr;

*aptr = *cptr;

*cptr = temp;

}
int main()

{ int a,

b, c;

printf("Enter three integers (a, b, c): ");

scanf("%d %d %d", Ca, Cb, Cc);

swapped(Ca, Cb, Cc);

printf("swapped: %d,%d,%d\n", a, b, c);

Q3) #include <stdio.h>

int Sum(int *arr, int

size) { int sum = 0;

for (int i = 0; i < size; i+

+) { sum += *(arr +

i);

return sum;

int main()

{ int n;

int

arr[n];

int

sum;

printf("Enter the number of elements in the array: ");

scanf("%d", Cn);
printf("Enter %d integers:\n",

n); for (int i = 0; i < n; i++) {


scanf("%d", Carr[i]);

sum = Sum(arr, n);

printf("The sum of the array elements is: %d\n", sum);

Q4) #include <stdio.h>

float secondhighest(float *arr, int size)

{ float h = 0;

float sh = 0;

for (int i = 0; i < size; i+

+) { if (*(arr + i) >

h) {

sh = h;

h = *(arr + i);

} else if (*(arr + i) > sh CC *(arr +

i) < h) { sh = *(arr + i);

return sh;

int main() {

float arr[20];

float sh;
printf("Enter 20 float numbers:\

n"); for (int i = 0; i < 20; i++) {

printf("Element %d: ", i +

1); scanf("%f", Carr[i]);

sh =secondhighest(arr,

20); if (sh == 0) {

printf("No second highest number found (all numbers may be the same).\
n");

} else {

printf("The second highest number is: %.2f\n", sh);

Q5) #include <stdio.h>

void sortfunction(int *arr, int *size, int

order) { int temp;

for (int i = 0; i < *size - 1; i++) {

for (int j = 0; j < *size - i - 1; j++) {

if ((order == 1 CC arr[j] > arr[j + 1]) || (order == 2 CC arr[j] < arr[j

+ 1])) { temp = arr[j];

arr[j] = arr[j +

1]; arr[j + 1] =

temp;

int main() {
int size;

int order;

printf("Enter the size of the array: ");

scanf("%d", Csize);

printf("Enter %d integers:\n",

size); int arr[size];

for (int i = 0; i < size; i++) {

printf("Element %d: ", i +

1); scanf("%d", Carr[i]);

printf("Enter 1 for Ascending order or 2 for Descending

order: "); scanf("%d", Corder);

sortfunction(arr, Csize, order);

printf("Sorted array:\n");

for (int i = 0; i < size; i+

+) { printf("%d ",

arr[i]);

Q6) #include

<stdio.h> int

main() {

int a[10];

for (int i = 0; i < 10;

i++) { a[i] = i * i;

printf("Array elements (squares of indices):\

n"); for (int i = 0; i < 10; i++) {


printf("%d ", *(a + i));

Q7) No, error message will be displayed because this assignment involves
incompatible pointer types.

It should be: p2 = (char *)p1;

You might also like