Pavel
What does int (*var)[size] mean?
Dereference var, access the result as array by index "size"
Ausir
Dereference var, access the result as array by index "size"
Ok and why if it's my attach to my shm segment i can access to var as var[i][j]?
Pavel
Ok and why if it's my attach to my shm segment i can access to var as var[i][j]?
Because var[0] does the same as *var. Can you provide the code example?
Pavel
I mean there's pointer to memory, it can point to an element or to an array. The same way you can have a pointer to pointer (like int**), then it can be 2d array, or array of pointers to elements, or pointer to pointer to an element, or pointer to an array. It's hard to guess what you mean without code
Ausir
@gameraccoon that's my code: https://pastebin.com/hLqWPLfz
Ausir
Could you explain me better? I did not understand
Pavel
@gameraccoon that's my code: https://pastebin.com/hLqWPLfz
Ok, now I see, I was talking about construction (*var)[size], I missed int at the beginning. int (var*)[N] is a declaration of a pointer to array of N elements. You can replace N with number and put it here. https://cdecl.org/
Pavel
I always discouraged by this C syntax
Ausir
I always discouraged by this C syntax
It's the only method for create 2d array into shm, better: that's the only method that I found on internet. Do you have any tips?
Pavel
It's the only method for create 2d array into shm, better: that's the only method that I found on internet. Do you have any tips?
If H and W are known at the beginning, and aren't very big (so it won't stackoverflow because of it), then you can just do int var[W][H]. Or you can do int** var; and allocate memory for sizeof(int)*M*N and address it as var[i+j*H]
Anonymous
hey guyz
Pavel
Then I would suggest to go with the second approach, and just calculate the index by yourself. Maybe someone else can suggest a better solution, I can't think of one right now.
Wendy
Am writing a program that allows user to input 4 number and I want the program to re arrange the number input by the user
Wendy
I need help
Anonymous
Am writing a program that allows user to input 4 number and I want the program to re arrange the number input by the user
Use std::vector std::vector<int> vec; for (int i = 0; i < 4; ++i) { vec.push_back(i); }
Anonymous
Good evening
Solo
How can I contact admin ?
Solo
Thinking about to promote discord server for developers
Anonymous
No thanks
Solo
We are paying for that ...
Hanz
Wallet intensifies
Ilya
/get cbook
Kishore
Anyone help me with c programming? I am actually beginner. I want to learn c from scratch
𝗠𝗿.𝗕𝗘𝗔𝗦𝗧
/get
𝗠𝗿.𝗕𝗘𝗔𝗦𝗧
Hi
Anonymous
/report
Anonymous
IMAGINE YOU ARE A DATABASE ADMINISTRATOR (DBA) FOR PENTAGON, US MINISTRY OF DEFENSE. YOU ARE HAVE A SPECIAL TASK OF DESIGNING DATABASE SYSTEM WHICH WILL BE USED WHICH HAS BEEN CONTRACTED TO PROVIDE SECURITY FOR GOVERNMENT LEADERS. OUTLINE IN DETAILS - THREE MAJOR FUNCTIONS OF THE DATABASE, - THE TABLES(FIVE) INVOLVED AND ITS USERS (AT LEAST THREE). any one can help me point of this assigment
Anonymous
It's so funny
Dada
What is the advantage of using pointer objects like MyClass* pMyClass; MyClass->MyFunction(); over this actual objects MyClass myClass; myClass.MyFunction();
Anonymous
What is the advantage of using pointer objects like MyClass* pMyClass; MyClass->MyFunction(); over this actual objects MyClass myClass; myClass.MyFunction();
because its a very good way to write a programm without using everytime copies and its good for big projects #efficient
Anonymous
because its a very good way to write a programm without using everytime copies and its good for big projects #efficient
Classes should implement mechanisms for memory allocation. You don't need to make a pointer. You have an internal handle in the class to manage this aspect. C++ favors RAII
Anonymous
but be careful pointer errors can be fatal and its also to for people without knowledge really dangerous
Anonymous
If you need to not copy the object, you pass a reference. Raw pointers in C++ are discouraged
Anonymous
I used pointers only in C.
Anonymous
I used pointers only in C.
If there are pointers they should be hidden in the class
Anonymous
If there are pointers they should be hidden in the class
yes.I dont know but i made in the past to many mistakes.I cant handle it
Dada
tat helps
Anonymous
lol, 2nd account?
Anonymous
Lol
Anonymous
At least use coherent phrases
Anonymous
`` char ch; while((ch = getch()) != '\n'); `` And `` int ch; while((ch = getch()) != '\n'); `` Here both works, iam confused here why. Which should i use or both are same?
Ilya
Because char can be converted to int. Every character has its digital code.
Anonymous
Oh so that means its same yah?
Ilya
Not at all. If you use 'char ch', you will receive characters: 'a', 'b', 'c' etc. If you use 'int ch', you will receive characters codes corresponding to the ASCII table
Anonymous
And what about this char arr[3]; Now let's say i read some character from file and store in arr using sscanf. Now what about this int ch = arr[0]
Anonymous
At what condition should i use int or char
Ilya
there will be the ASCII code in 'int ch' of the very first character arr[0]
Ilya
If you want to work with strings and characters - use char
Ilya
If you want to create magic with ASCII codes offsets, use int
Ilya
but you also can write smth like that: char c = 'a'; c++;
Ilya
but note, that, if you create string (char *arr[3]), the incrementing operation will mean another operation
Ilya
there will be pointer arithmetics
Ilya
I don't know how to explaing it correctly. But you can read about bit operators '< <' and '> >'
Ilya
Offset is about shifting smth.
Mohit Kumar
Sorry
Anonymous
Thanks for you help dude
Anonymous
Can i see c library functions defination?
Anonymous
Any site out there
Anonymous
I searched but didn't found
Ilya
you have it on your system
Ilya
look for "include" path or smth like that
Ilya
you also can open IDE (CodeBlocks for example), than right click on the function and then smth like "Got to definition"
Anonymous
Basically i am using android so its little hard to see properly
Ilya
https://en.cppreference.com/w/c
Igor🇺🇦
Basically i am using android so its little hard to see properly
Why do you need definition? That's kind of intentional - to hide definition and show declaration only
Anonymous
No just for research only
Igor🇺🇦
No just for research only
You can check gcc source code if you're that interested https://github.com/gcc-mirror/gcc
Anonymous
Ok
Ilya
And also clang)
Anonymous
Ok sure
Thierry
whats the best way to set the value of an array field of a structure pointer in C? is it really like the following? T arr = { ... }; // size n memcpy(mystruct->arrfield, arr, n);
Ilya
You need to wrap memcpy() in function to check some things: 1) you've allocated memory for struct->arr 2) you've put the correct size (n) to memcpy