Pointer in c program problems
#include <stdio.h>
int main()
{
int i = 34;
int *j = &i;
int **k = &j;
int ***l = &k;
// int *ch_integer=&i;
printf("the value of i is %d \n ", i);
printf("the value of i is %d \n ", *(&i));
printf("the address of i is %u \n ", &i);
printf("the add of j is %u \n ", &j);
printf("the value of j is %d \n ", j);
printf("the value of j is %d \n ", *(&j));
printf("the value of k is %d \n", *(&k));
printf("the add of l is %d \n", (&l));
printf("the value of l is %d \n", *(&l));
// printf("the value of i is %d ", i);
return 0;
}
#include <stdio.h>
int main()
{
int x = 9;
int *y = &x;
printf("the add of x is %u \n", &x);
printf("the value of x is %d \n", *(&x));
printf("the value of x is %d \n", *y);
printf("the add of y is %u \n", &y);
printf("the value of y is %d \n", y);
return 0;
}
#include <stdio.h>
void add(int a);
int main()
{
int i = 4;
printf("the value of i is %d \n", i);
add(4);
printf("the add of i is %u \n", &i);
return 0;
}
void add(int a)
{
printf("the add of a is %u\n", &a);
}
#include <stdio.h>
void change_10(int *a);
int main()
{
int x;
x = 10;
printf("the value of x before is %d\n", x);
change_10(&x);
printf("the value of x after is %d ", x);
return 0;
}
void change_10(int *a)
{
int temp;
temp = *a * 10;
*a = temp;
}
#include <stdio.h>
int sum(int *a, int *b);
int avg(int *a, int *b);
int main()
{
int x, y, results, results1;
printf("Enter the value of X and Y:\n");
scanf("%d%d", &x, &y);
results = sum(&x, &y);
printf("the value of sum is %d\n", results);
results1 = avg(&x, &y);
printf("the value of avg is %d\n", results1);
return 0;
}
int sum(int *a, int *b)
{
return *a + *b;
}
int avg(int *a, int *b)
{
return (*a + *b) / 2;
}
#include <stdio.h>
void SumandAvg(int a, int b, int *sum, float *avg)
{
*sum = a + b;
*avg = (float)(*sum / 2);
}
int main()
{
int x, y, sum;
float avg;
x = 267;
y = 120;
SumandAvg(x, y, &sum, &avg);
printf("The value of sum is %d \n", sum);
printf("The value of avg is %f \n", avg);
return 0;
}
#include <stdio.h>
int main()
{
int i = 5;
int *j = &i;
int **k = &j;
printf("the value of i is %d ", *(*k));
return 0;
}
#include <stdio.h>
void change(int a)
{
int temp;
temp = a * 10;
a = temp;
}
int main()
{
int x = 10;
printf("The value of x before %d\n", x);
change(x);
printf("The value of x after %d", x);
return 0;
}
#include <stdio.h>
void swap(int *a, int *b);
int main()
{
int x = 32, y = 45;
printf("the value of swap before %d , %d \n ", x, y);
swap(&x, &y);
printf("the value of swap after %d , %d \n ", x, y);
return 0;
}
void swap(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
No comments:
Post a Comment