c 2b 2b array

Solutions on MaxInterview for c 2b 2b array by the best coders in the world

showing results for - "c 2b 2b array"
Antonio
11 May 2020
1#include <iostream>
2using std::cout;
3
4int a[] = { 1, 2, 3, 4, 5 };
5int counta()
6  {
7  return sizeof( a ) / sizeof( a[ 0 ] );  // works, since a[] is an array
8  }
9
10int countb( int b[] )
11  {
12  return sizeof( b ) / sizeof( b[ 0 ] );  // fails, since b[] is a pointer
13  }
Laura
11 Jul 2020
1int foo [] = { 16, 2, 77, 40, 12071 };
Cloé
01 Jan 2020
1int nCount[] = {1, 2, 3, 4, 5};
Maximilien
16 Feb 2019
1#include <iostream>
2#include <array> //for using std::array
3
4int main()
5{
6
7	int example[5];//array on stack
8	int* another = new int[5];//array on heap
9	delete[] another;//freeing up memory on heap
10	example[0] = 1;
11	example[1] = 2;
12	example[2] = 3;
13	example[3] = 4;
14	for (int i = 0; i < 5; i++) {
15		example[i] = 2;
16	}
17	int* ptr = example;//arrays are just pointers to the begining of the block of memory
18	example[2] = 5;
19	*(ptr + 2) = 6;//adding 4+4 bytes to ptr
20	std::cout << example[2] << std::endl;//output => 6
21	*(int*)((char*)ptr + 8) = 8;//adding 8 bytes to ptr using ptr arithmetic
22	std::cout << example[2] << std::endl;//output => 8
23	//std::array provide some additional functionality like bounce checking size checking but do have a performance overhead
24	std::array<int,5> stda;//creating an array named stda of int 5 size
25	std::cout << stda.size() << std::endl;//will output size of std::array ,output =>5   
26    std::cin.get();
27}
Molly
21 Jan 2017
1int foo [5];
Sami
18 May 2020
1const int len = 3;
2int arr[len];
3
4arr[0] = 4;
5
6int abc[4]{0,12,3}
similar questions
queries leading to this page
c 2b 2b array