Hanz
#ASK What is __attribute__ and ((__packed__))? Is that gcc extension or standard? im looking at sds source code
Hanz
oh i found it, its macro and gcc extension
VRJ
How to find my age in c
Anonymous
How to find my age in c
U dont know your own age?
Vlad
How to find my age in c
Interesting question for sure
Anonymous
Your mother might know...
Anonymous
give me some suggestion i an confused with the question
Google for "c program to sort struct using pointers"
Anonymous
Or something like that
Anonymous
Hello friends
Anonymous
Am new to programming ..buh i prefer learning c language first...any guide or advice?
Anonymous
Am new to programming ..buh i prefer learning c language first...any guide or advice?
Advice: go with something easier than C, for example: python, that's how I started
Vitrag
There is a website for Indians called NPTEL where they teach for free
Anonymous
Advice: go with something easier than C, for example: python, that's how I started
ooh ohk...But C provides the basics... Thats what i have read
Vitrag
Programming in C++ - - Announcements https://onlinecourses.nptel.ac.in/noc21_cs55/announcements
Vitrag
They teach from basics
Anonymous
ooh ohk...But C provides the basics... Thats what i have read
C is quite low level and requires laods of manual work. it's *basic* heh, python is quite opposite of that, it's really high level and doesn't require much manual things
Parth
Anyone doing c++
Ludovic 'Archivist'
Am new to programming ..buh i prefer learning c language first...any guide or advice?
If you really want to learn C, I would advise to use a very predictable compiler for it like Plan9 C Compiler rather than a mainstream one, for GCC and Clang as well as MSVC have optimization quirks that may prove to make learning harder
MRT
hey guys , can anybody give me a example how to pause and resume data in tcp ? icreate a simple real chat api ,I want to allow the user to stop ,pause and resume the file when uploading or download
chronicle
#include <iostream> #include <stdio.h> using namespace std; class student { int rno; char name [20]; int s1, s2, s3, tot; float percent; public: void getdata (void); void display (void); void calc (void); }; void student::getdata (void) { cout << "enter roll no"; cin>>rno; cout<<"enter name"; cin>>name; cout<<"enter marks"; cin>>s1>>s2>>s3; } void student:: calc(void) { tot=s1+s2+s3; percent=tot/3; } void student::display (void) { cout<<"\n roll no "<<rno; cout<<"\n name "<<name; cout<<"\n marks "<<s1<<" "<<s2<<" "<<s3; cout<<"\n total "<<tot; cout<<"\n percent "<<percent; } void main() { student s[5]; int i; for (i=0; i<3;i++) { s[i].getdata(); s[i].calc(); s[i].display(); } return 0; }
chronicle
error: ‘::main’ must return ‘int’ void main() ^
chronicle
how to resolve this?
Lenin
/get cbook
Anonymous
how to resolve this?
Change void main() to int main() The compiler cant give you a more friendlier error message.
Anonymous
What's the issue with this: int dfs(int &grid[][5], int i, int j, bool &visited[]) error: declaration of 'grid' as array of references int dfs(int &grid[][5], int i, int j, bool &visited[]) {
Anonymous
What's the issue with this: int dfs(int &grid[][5], int i, int j, bool &visited[]) error: declaration of 'grid' as array of references int dfs(int &grid[][5], int i, int j, bool &visited[]) {
What do you want the grid parameter to be? You have declared grid to be an array of arrays of int references. The grid parameter in your case is int& (*grid)[5]. You cant have an array of references or a pointer to it.
Anonymous
can't i do int &grid[][5]?
Anonymous
umm it's a variation of Flood Fill Algo that I am implementing I need to pass the 2D array as reference
If you want to pass it by reference then you have to use both the dimensions. Suppose the first dimension is also 5, then your function declaration should be int dfs(int (&grid)[5][5], int i, int j, bool (&visited)[5]) Change the dimensions of grid and visited as per your requirements.
Anonymous
yes i mean i can do vector<vector<int> > &matrix but again int (&grid)[5][5] and bool (&visited)[5]) didn't work out :/
Show me the arguments to the function (as in how you are calling the DFS function) and also show me how the arguments are defined. It should work if you call it right.
Anonymous
I am trying to automate sign up on a site But there's no post request in network
smene
Hello everyone, guys. I would like to create an internal gta 5 mod menu, any advice? I don't know where to start from..
Ehsan
Hello! I want to make an array of mutexes, so I did the following in the class: cpp private: std::array<std::shared_mutex, 14> locks_; The problem is the mutex die before I even start. libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument how do I make it live as long as the object lives?
Anonymous
I store it in an std::array
I need to see the code where you access the mutexes. This error happens when you try to access a mutex before it is completely constructed or after it has been destroyed. So without seeing the code, we cant do much
Nur
I need a basic help
Nur
How do I print the sum of 1.0 and 2.0 as 3.0 not 3?
Nur
I am trying double x=1.0; double y=2.0; double z; z = x+ y; cout << z; It gives 3 not 3.0
Nur
Is it necessary to add std:: if I am using "using namespace std;" ?
Anonymous
Is it necessary to add std:: if I am using "using namespace std;" ?
Not necessary. The reason why I added it is to show that showpoint is also in the std namespace
Nur
Thanks a lot
Nur
It worked 😁
Sandeep
int mergeSort(int arr[], int array_size) { int temp[array_size];👈👈👈👈 return _mergeSort (arr, temp, 0, array_size - 1); }
Anonymous
What should I do
Use a vector or dynamic arrays
Sandeep
Normal array
Anonymous
Normal array
The dimensions of normal arrays must be a integral constant expression. You cant use a variable that is not a constexpr. VLA is not supported in C++.
Sandeep
Still wont work.
What is a constant expression..
Sandeep
4+5??
Anonymous
What is a constant expression..
A value that is known at compile time.
Sandeep
A value that is known at compile time.
Will it work if array_size Is evaluated before creating this array..? (Then it is know in compile time??)
Sandeep
int main() int arr[] = { 1, 20, 6, 4, 5 }; int n = sizeof(arr) / sizeof(arr[0]);👈👈👈 int ans = mergeSort(arr, n); cout << ".Number of inversions are " << ans; return 0; }
Anonymous
int main() int arr[] = { 1, 20, 6, 4, 5 }; int n = sizeof(arr) / sizeof(arr[0]);👈👈👈 int ans = mergeSort(arr, n); cout << ".Number of inversions are " << ans; return 0; }
Here n is a plain int variable that is still considered to not be a compile time constant. Make it constexpr int n = sizeof(arr)/sizeof(arr[0]). Then you can use n to create arrays of length n. But this still wont work out if you intend to pass n as an argument to another function
Piyushree Rani
Hey..I desires to learn c and c++ concepts..so I have joined this platform..I hope this platform will help me in defining and understanding the programming concepts in every aspect
Piyushree Rani
Sure, when you have doubt, feel free to ask
Thanks..Actually I'm new to this beautiful computer science platform. So I am in need to learn all the Java concepts readily from the beginning.
@𝑺𝒐𝒃𝒌𝒂
Hi! Is there any specific criterion to define a member function of a class as an inline function? Or only if a function definition is short?
Anonymous
Helo
Anonymous
Hi! Is there any specific criterion to define a member function of a class as an inline function? Or only if a function definition is short?
There is no specific criterion. If a member function is defined inside the class body it is implicitly inline. But note that the meaning of the keyword "inline" has been changed since the C++17 standard. Previously inline used to be an indicator to the compiler to possibly inline calls to the function at the call site itself rather than going through the time consuming procedure call option. This was just a hint and the compiler could ignore this inline directive. But since C++17, the meaning of the keyword inline has been changed so as to match ODR rules (One Definition Rules) i.e. to not violate them. The new definition allows more than one definition of inline function across translation units and to ensure all such accesses point to the same address. You can read about it here. inline keyword can now be used with variables as well.
Anonymous
Why are we casting it into( int*) Why not int
Because it is a region of array_size integers allocated on the heap and the return value of malloc is a pointer to the first int in this region returned as a void* pointer. In C, you should not cast the return value from malloc. But C++ requires such a cast from void* to int*. But in C++, you should not use malloc at all. You should be using smart pointers instead to manage memory or you can use new/delete directly if for some reason you cant use smart pointers.
Anonymous
Ok.! I referred particularly to the implicit inline when a member function is defined inside the body class. My intention behind the question is: in my code, I noticed that getters(accessors) are short. So, is that a good practice defining all of them as an inline function (implicitly)?
As long as the code for such functions is short and simple like the getters and setters and it doesnt clutter the class definition (I.e. the meaning and the point of the class should still be visible) then it is generally good practice to define them inside the class.
Good
I have one question in CMake can I post it here?