Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c

Pointer and one dimensional array in C++

Posted on January 12, 2017June 26, 2020

Table of Contents

  • Pointer and one dimensional array in C++
    • Array with pointer

Pointer and one dimensional array in C++

In this tutorial, we will try to understand Pointer and one dimensional array in C++.
First, we will look at array.

What is the array?
Array is a data type in many programming languages and array is one of structured data types.
Array contains multiple elements.
Elements are organised contiguously in memory.
Array  contains homogeneous elements therefore array always contains the same data type.

What is a pointer?
Pointer is a variable that stores another variable’s  memory address.

Here is an example of one dimensional array in C++. We must understand array structure before learn this chapter in C++

 

program 1

#include <iostream>
using namespace std;
int main()
{
int marks[]{34,56,75,68,97,43,24,52,47,87
};
cout << “List of marks” << endl;
cout << “\nmarks 1:  ” << marks[0];
cout << “\nmarks 2:  ” << marks[1];
cout << “\nmarks 3:  ” << marks[2];
cout << “\nmarks 4:  ” << marks[3];
cout << “\nmarks 5:  ” << marks[4];
cout << “\nmarks 6:  ” << marks[5];
cout << “\nmarks 7:  ” << marks[6];
cout << “\nmarks 8:  ” << marks[7];
cout << “\nmarks 9:  ” << marks[8];
cout << “\nmarks 10:” << marks[9];

return 0;
}

In this program, we have displayed the element of one d array in C++. In this case,10 elements of an array are displayed.

 

Array with pointer

How are pointers and arrays related?

arrayname=point to the first element in the array

&arrayname=point to the address of first element in the array

&arrayname[0]=point to the first element in the array

 

Program 2

#include <iostream>

using namespace std;

int main()
{
int marks[]{34,56,75,68,97,43,24,52,47,87};
cout <<“address of marks: “<<marks<< endl;
cout <<“address of marks: “<<&marks<< endl;
cout <<“address of marks: “<<&marks[0]<< endl;
return 0;
}

 

 

 

 

Related Links

Pointers in C Programming language

Pointers in C++ Programming language

Pointer to pointer in C Programming Language

Pointer to pointer in C++ Programming Language

Pointers with one d array in C language

Structure with pointers in C Language

Structure with pointers in C++ Language

Related

Recent Posts

  • Subtract two numbers using method overriding
  • PHP Star triangle Pattern program
  • Using function or method to Write temperature conversion : Fahrenheit into Celsius
  • Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user
  • Write temperature conversion program: Fahrenheit into Celsius
  • How to write a program to convert Fahrenheit into Celsius

tag

Addition (6) Array (38) C++ language (91) C language (98) c sharp (23) Division (6) Function (29) if else (32) Java language (102) JavaScript (5) loops (137) Multiply (7) Oop (2) patterns (65) PHP (13) Python Language (38) Subtraction (7) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2025 Code for Java c | Powered by SuperbThemes