Anonymous
#include <stdio.h> void input(int r, int *ptr1, int *ptr2); void res(int r, int *ptr3, int *ptr4, int *add); void display(int r, int *add); int i, j; void main() { int r, c; printf("Enter the row and column of matrix:"); scanf("%d%d", &r, &c); if (r == c) { int m1[r][r], m2[r][r]; int *p1, *p2, *add=0; p1 = &m1[r][r]; p2 = &m2[r][r]; input(r, p1, p2); res(r, p1, p2, add); display(r, add); } else printf("The matrix cannot be added"); } void input(int r, int *ptr1, int *ptr2) { printf("Enter elements of matrix 1:"); for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { scanf("%d", (*(ptr1 + i) + j)); } } printf("Enter elements of matrix 2:"); for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { scanf("%d", (*(ptr2 + i) + j)); } } } void res(int r, int *ptr3, int *ptr4, int *add) { for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { *(*(add + i) + j) = *(*(ptr3 + i) + j) + *(*(ptr4 + i) + j); } } } void display(int r, int *add) { printf("Addition matrix:\n"); for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { printf("%d ", *(*(add + i) + j)); } printf("\n"); } }
Anonymous
Someone help me to debug please
Anonymous
what does this pointer is implicitly casted to?
Anonymous
It's a pretty stupid concept that you can search online :) It's funny how you didn't even try yo understand my code before starting with other questions
"The malloc() function in C++ allocates a block of uninitialized memory and returns a void pointer to the first byte of the allocated memory block if the allocation succeeds. If the size is zero, the value returned depends on the implementation of the library. It may or may not be a null pointer." This is what I found online Do you think is it easy to understand for high school guy
Anonymous
No
Okey
Anonymous
No
I am getting indirection requires pointer operand error Can help with this then?
Anonymous
Yes
It is related to dynamic memory I guess It will be used in linked list or any other dynamic structure
Mat
It is related to dynamic memory I guess It will be used in linked list or any other dynamic structure
You use malloc/calloc/realloc/free to use dynamic memory allocation, yes
Anonymous
Okey thanks
Anonymous
new
This is a alternative of malloc but doesn't return void as I have read somewhere online
Anonymous
Lol
Me noob sir
Mat
new
new is C++
Anonymous
new is C++
Of course
Anonymous
Not a function
Anonymous
And it calls default initilizer for the type
Anonymous
It is Cpp way of dealing with dynamic memory
The c++ way is smart pointers :)
Anonymous
Jøhn
Offtopic but does anyone know any chats about Ruby?
Jøhn
@it_chats
OK thanks
Dima
@it_chats
Rest in pepperoni; inb4 all these groups are being spammed by indians.
Anonymous
Hi
#Dure-dure
🤝
Anonymous
HELP ME
Anonymous
Anonymous
why it does not see the directory
Anonymous
?
I_Interface
Anonymous
:)
Anonymous
Rest in pepperoni; inb4 all these groups are being spammed by indians.
Be sincere admin Never blame any nationality I also have blocked many spammers From different countries such as ghana, Poland,Philippines, even USA But I never blame their nationality We are here to talk about programming in c++ I am still confused little bit with ** 😁😁😁😄😆😆🙂
Dima
What the hell is going on here
Anonymous
but this is true so psst.
I should remain silent Some people should be in myth That's ok I have talked with many better foreigners including students and programmers
Dima
I don’t care, just discuss your double pointer problem
Anonymous
I don’t care, just discuss your double pointer problem
Can you give a very simple example of use of ** in program with less complex functions My teacher said that it's pointer which is pointing to other pointer I thought then why I will use it
Dima
for example when you need to have heap-allocated array with heap allocated objects for example (not so good example), there’s no really good use for double pointers nowadays
Anonymous
Does cpp map always store the keys in ascending order?
Anonymous
If I do for(auto &x:mp){ cout<<x.first<<" "; } Will the above always print the keys in ascending order?
Anonymous
Does cpp map always store the keys in ascending order?
It provides the iterators that give you access to the elements in ascending order
Anonymous
ok
Anonymous
Not always
Anonymous
and when is "NoT" the case?
Anonymous
You can provide std::map with your own compare function
Anonymous
Which will compare elements of map
Anonymous
By default it is std::less
Anonymous
So, keys not stored in ascending order?
Anonymous
std::less is ascending or descending?
Anonymous
Anonymous
std::less is a < b
Anonymous
If I do for(auto &x:mp){ cout<<x.first<<" "; } Will the above always print the keys in ascending order?
Anonymous
I'm iterating in a for each loop
Anonymous
If type of the map is std::map<T1, T2>, the answer is yes
Anonymous
Of course it would be like that.
Anonymous
What else can it be?
Anonymous
I've told you already
Anonymous
That you can provide your own comparison functions
Anonymous
hmm
Anonymous
thnax
Anonymous
Learn how to work with the documentation already
Anonymous
I was asking for simple map<t1,t2> and nothing else. Had I used something else, then I myself would have realised that keys will not be stored in the ascending order.
Ибраги́м
fixing c++ with epochs https://vittorioromeo.info/index/blog/fixing_cpp_with_epochs.html
Kusumanadh
Hi