The following code shows how to Create and Display Elements of an Array using Pointers in C. Also, the address of the elements also printed along with the element value.
// Read and display elements of an array using pointers
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int i, total, number;
printf("How many elements do you want in the array?");
scanf("%d", &total);
double *arr=malloc(total*sizeof(int));
for(i=0;i<total;i++)
{
*(arr+i)=sqrt((i+1)*10);
printf("%lf %p\n", *(arr+i), (arr+i));
}
return 0;
}
Output
How many elements do you want in the array?10
3.162278 0x55736359cac0
4.472136 0x55736359cac8
5.477226 0x55736359cad0
6.324555 0x55736359cad8
7.071068 0x55736359cae0
7.745967 0x55736359cae8
8.366600 0x55736359caf0
8.944272 0x55736359caf8
9.486833 0x55736359cb00
10.000000 0x55736359cb08
Further Reading
50+ C Programming Interview Questions and Answers
C Program to Find Factorial of a Number
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- Extended Reality
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML