0 évaluation0% ont trouvé ce document utile (0 vote)
10 vues1 page
This document contains two C program examples using pointers. The first program accesses array elements using a pointer by taking the address of each element and printing the values. The second program adds two numbers by taking the addresses of the variables containing the numbers, dereferencing the pointers to access the values, adding them, and printing the sum.
This document contains two C program examples using pointers. The first program accesses array elements using a pointer by taking the address of each element and printing the values. The second program adds two numbers by taking the addresses of the variables containing the numbers, dereferencing the pointers to access the values, adding them, and printing the sum.
This document contains two C program examples using pointers. The first program accesses array elements using a pointer by taking the address of each element and printing the values. The second program adds two numbers by taking the addresses of the variables containing the numbers, dereferencing the pointers to access the values, adding them, and printing the sum.
1. Access Array Elements Using Pointer #include <stdio.h> int main(){ int data[5], i; printf("Enter elements: "); for(i=0;i<5;++i) scanf("%d",data+i); printf("You entered: "); for(i=0;i<5;++i) printf("%d\n",*(data+i)); return 0; } 2. C program to add two numbers using pointers #include <stdio.h> int main() { int first, second, *p, *q, sum; printf("Enter two integers to add\n"); scanf("%d%d", &first, &second); p = &first; q = &second; sum = *p + *q; printf("Sum of entered numbers = %d\n",sum); return 0; }