CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
why all three methods have same output?
One and two i belive are proper and there is no index check in c++ array for method 1. what i believe is true...correct ?
what is round bracket in size allocation for method 3? it is non array and its like normal int call i.e. int a(3); means a = 3...now, int* p = new int(3); means p is pointer of int whose value is 3... in short, its not pointer array.
thanks to thread below or refer first comment of code below :
https://www.sololearn.com/Discuss/2651350/?ref=app
https://www.bogotobogo.com/cplusplus/memoryallocation.php
*/
#include <iostream>
using namespace std;
void test_1()
{
int* p = new int;
cout << p << " " << &p[0];
cout << endl;
cout << p + 1 << " " << &p[1];
cout << endl;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run