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
    • Related

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

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes