Harsh
Try calling func as fun(&arr1); Then it makes sense to use double pointers
In this way using namespace std; void fun(int **sac) { **sac[1][0]=4; } int main() { int arr1[2][2]={{1,2},{0,5}}; fun(&arr1); cout<<arr1[1][0]; }
Anonymous
you can
i want to do it with pointer
Андрей
i want to do it with pointer
int (*arr)[2][2] is pointer to array
Harsh
error is coming
What error?
Dima
Lol
Anonymous
11 11 C:\s\2d using pointer.cpp [Error] cannot convert 'int (*)[2][2]' to 'int**' for argument '1' to 'void fun(int**)'
Андрей
why pass 2d array using pointer to pointer if you can use pointer ???
Андрей
wtf?!?!?!
Anonymous
int (*arr)[2][2] is pointer to array
i am now allowed to pass[][] in function
Андрей
you can't pass 2d array, it's not like int **arr = new int[rows]; for (...) arr[i] = new int[cols];
Андрей
Anonymous
what's the task ?
task is simple create n*n in main function and do a sum of there dialgonals but the condition is use a function to insert elements in the matrix using pointer size should be passed explicitly
Anonymous
fun(arr,size)
Anonymous
bot dimensions are of same size
Anonymous
suppose i created in int main() { int arr[2][2];
Anonymous
then i need to pass fun(arr,2)
Anonymous
Then why you want it **? Using *arr1[] on &arr1 is best I say
i dont want the question is that what i am supposed to do
Harsh
then i need to pass fun(arr,2)
In this way using namespace std; void fun(int *sac) { *sac[1][0]=4; } int main() { int arr1[2][2]={{1,2},{0,5}}; fun(&arr1); cout<<arr1[1][0]; }
Harsh
it gives error
This too eh?
Anonymous
check plzz
Anonymous
it gives error
This is so cool!!
Anonymous
This is so cool!!
what happened sir??
Dima
Anonymous
what happened sir??
How tf I can know?
Anonymous
How tf I can know?
bro donot abuse
Dima
Stop begging
Anonymous
bro donot abuse
I'm not a bro, I'm the sir
Андрей
Dima
hit or miss
Harsh
check plzz
What errors does it give u?
Harsh
Only sac[1][0]=4
Nah check my code further down I gave another
Anonymous
What errors does it give u?
11 11 C:\s\2d using pointer.cpp [Error] cannot convert 'int (*)[2][2]' to 'int*' for argument '1' to 'void fun(int*)'
Anonymous
Anonymous
i think the error is there because when we acces element using pointer, we dont use that rather *(sac+1) or something like that.
Anonymous
oh god..i have forgotten how to access it in case of 2d array
Stanislav
int ***sac :)
Anonymous
in 2d array *(*sac+1)+j)
Harsh
in 2d array *(*sac+1)+j)
http://www.cplusplus.com/forum/general/170857/ This can help
Anonymous
int ***sac :)
it also gives error
Till
Dev-C++??? Srly? Use normal IDE, delete it
Till
why??
outdated shit
Harsh
arr1[1][0] == *(*(arr1+1)+0)
Harsh
Anonymous
why in my compiler this is not working
Nameful
Anonymous
this is not workin on gdb online compiler
Nameful
also, I would recommend installing gcc/g++ locally
Anonymous
Anonymous
arr1[1][0] == *(*(arr1+1)+0)
is is same but we can't use it while using pointer
Anonymous
send error
annot convert ‘int (*)[2]’ to ‘int**’ for argument ‘1’ to ‘void fun(int**)’ fun(arr1); ^
Anonymous
tried on gcc as well
Anonymous
#include<iostream> using namespace std; void fun(int **sac) { sac[1][0]=4; } int main() { int arr1[2][2]={{1,2},{0,5}}; fun(arr1); cout<<arr1[1][0]; }
Anonymous
showing error
what about when you just print the value at sac[1][0]? does that show error too?
I_Interface
yup
u need to put the size of array into func's parameters
Anonymous
#include<iostream> using namespace std; void fun(int sac[][2]){ sac[1][0]=4; } int main(){ int arr1[2][2]={{1,2},{0,5}}; fun(arr1); cout<<arr1[1][0]; } only this works
I_Interface
int fun(int arr[2][2]) { return arr[1][0] = 5; } int arr[2][2] = { {1,2}, {3,4} }; fun(arr); std::cout << arr[1][0];
Anonymous
that is the question
Anonymous
Love to be here... After all God and nature are all programmers too
Dima
What
Dima
Anonymous
:)