Language
C++
Compiler
gcc 12.1.0
Options
Warnings
Optimization
Don't Use Boost
C++11
-pedantic
#include <iostream>
// * PLAYING WITH POINTERS!!!
using namespace std;
void example(string *pizzas, int i_row, int i_column);
int main(){
int row=2,column=12;
string pizzas[row][column] {{"pizza0","pizza1","pizza2","pizza3","pizza4"},
{"pizza5","pizza6","pizza7","pizza8","pizza9"}};
int i_row = sizeof(pizzas)/sizeof(pizzas[0]),i_column = sizeof(pizzas[0])/sizeof(pizzas[0][0]);
//string * sample = &pizzas[0];
//const int size{sizeof(pizzas)/sizeof(pizzas[0])};
// ? why i get *cannot convert ‘std::__cxx11::string (*)[column] {aka std::__cxx11::basic_string<char>
// ? (*)[column]}’ to ‘std::__cxx11::string* {aka std::__cxx11::basic_string<char>*}’ for argument ‘1’ to ‘void example(std::__cxx11::string*, int*, int*)’*
example(pizzas, i_row, i_column);
/*
cout<<*sample<<'\n';
sample = &pizzas[4];
cout<<*sample<<'\n';
*/
}
void example(string *pizzas, int i_row, int i_column){
// ? also i get error forbids comparison between pointer and integer
//row
for (size_t i = 0; i != i_row; i++){
//colum
for (size_t j = 0; j != i_column; j++)
cout<< pizzas[i][j] << ' ';
cout<<endl;
}
}
$ g++ prog.cc -Wall -Wextra -I/opt/wandbox/boost-1.79.0-gcc-12.1.0/include -std=gnu++2b
Exit Code:
1