DSA 1.8 : Pointers

PHOTO EMBED

Mon Feb 27 2023 13:43:19 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c

#include <iostream>
using namespace std;

int main()
{
    int *p;
    p= (int *)malloc(5*sizeof(int));  
    //will allocate memory for 5 integers, so it is an array of integers and it is assigned to p
    
    //initializing the values
    p[0] = 10;
    p[1] = 20;
    p[2] = 30;
    p[3] = 40;
    p[4] = 50;

    
    for(int i=0; i<5; i++)
    {
        cout << p[i] << endl;
    }
    
    return 0;
}
content_copyCOPY

Creating an array in a heap using pointer using C language.