?
Maybe you mean "function prototype"
YES im talking about the function prototype
ببب ب
In C++20, does copy elision happen on co_yield? At the moment I'm returning an rvalue reference, but I understand this is unnecessary on ordinary functions, and bad practice since it miscommunicates intent.
Ah Fan
hello guys, i need some helps to finish ny works. rn im working on an ordering system, the system will give me a 6 percent discount if i enter 'AE6GY' Code. i already create a switch statement but i didnt get a right answer. can any of you guys can spot the error. thanks
Ah Fan
#include <iostream> using namespace std; void menu() { cout << "******Welcome to the Farhan's Restaurant******" << endl; cout<<"_________________________________________________"<<endl; cout<<"No. Menu Price"<<endl; cout<<"1. Cheese Burger RM 8"<<endl; cout<<"2. Chicken Wings(6 pieces) RM 10"<<endl; cout<<"3. 12\" Pepperoni Pizza RM 20"<<endl; cout<<"4. Fries RM 5"<<endl; cout<<"5. Onion Rings RM 6"<<endl; cout<<"6. Pepsi RM 2"<<endl; cout<<"7. Mineral Water RM 3"<<endl; } main() { string phone; //we use string so that the 0 value can be displayed string Name; cout<<"Please enter your name :"; getline(cin,Name); //to ensure we can input two names at once cout<<"Please enter your phone number :"; cin>>phone; float jum; promo; int n; int qty[7]; int no[7]; long price[7],tot[4]; string name[7]; float change,pay,discount; menu(); cout<<""<<endl; cout<<"How many types of menu do you want: "; cin>>n; if(n>0 && n<=7) //loop for menus { for(int i=0; i<n;i++) { cout<<"Enter your choice "<<i+1<<"="; cin>>no[i]; cout<<"Enter quantity ="; cin>>qty[i]; if(no[i]==1) { name[i]="Cheese Burger"; price[i]=8; tot[i]=price[i]*qty[i]; } else if(no[i]==2) { name[i]="Chicken Wings(6 pieces)"; price[i]=10; tot[i]=price[i]*qty[i]; } else if(no[i]==3) { name[i]="12\" Pepperoni Pizza "; price[i]=20; tot[i]=price[i]*qty[i]; } else if(no[i]==4) { name[i]="Fries"; price[i]=5; tot[i]=price[i]*qty[i]; } else if(no[i]==5) { name[i]="Onion Rings"; price[i]=6; tot[i]=price[i]*qty[i]; } else if(no[i]==6) { name[i]="Pepsi"; price[i]=2; tot[i]=price[i]*qty[i]; } else if(no[i]==7) { name[i]="Mineral Water"; price[i]=3; tot[i]=price[i]*qty[i]; } jum=jum+tot[i]; } system("cls"); menu(); cout<<"_________________________________"<<endl; cout<<"Your choice is :"<<endl; for(int i=0;i<n;i++) //loop for order quantity { cout<<""<<qty[i]<<" portion "<<""<<name[i]<<endl; cout<<"Price/portion ="<<price[i]<<endl; cout<<"Total Price "<<name[i]<<"="<<tot[i]<<endl; } cout<<"We only accept cash payments"<<endl;//I state that my shop only receive cash payments cout<<"paid : Rm "; cin>>pay; cout<<"Do you have a promo code?"<<endl; cin>>promo; switch(promo) { case 'AE6GY': discount = (6*pay)/100; change= pay-discount-jum; break; } // change=pay-jum; cout<<"________________________________"<<endl; cout<<"Your name is:"<<Name<<endl; cout<<"Phone no is:"<<phone<<endl; cout<<"Change: Rm"<<change<<endl; cout<<"Thank you for visiting"; } else cout<<"Code your input doesnt exist"; return 0; }
Anonymous
Post data to ssl website using winapi cpp Is it possible
Hitesh
Hey, any one has used Xtensor library?
Alaa
Hello guys
Alaa
Can you recommend me some good books or studying recourses to learn C++?
Alaa
I’m a student in the international informatics Olympiads and I need something good to be able to compete I’d be happy if you can help
AmR
Who know and class for personal name cases ?
Alaa
Ludovic 'Archivist'
Arnold
Can you recommend me some good books or studying recourses to learn C++?
unironically I passed C/C++ in uni all thanks to indian youtube tutorials
Arnold
it's sometimes hard to understand what they're saying but the content itself is amazing
D
Anyone know gdbm
Anonymous
@SilhouetteInDark why do you think are function declarations there in C and C++ ? why we need to write a function declaration on top of a function call when the actual function definition is below that function call
They are not always required. Only in cases where the call to the function happens but the definition is not in the same translation unit (or if it is in the same translation unit but it is defined after the actual call to the function) do we need the function declaration. There are 15000 members in the group. So don't tag people asking them to answer your questions. Just ask your question directly and someone might find the time to answer it
?
They are not always required. Only in cases where the call to the function happens but the definition is not in the same translation unit (or if it is in the same translation unit but it is defined after the actual call to the function) do we need the function declaration. There are 15000 members in the group. So don't tag people asking them to answer your questions. Just ask your question directly and someone might find the time to answer it
i know that a function declaration must be there when the function definition is not in the same translation unit or when a function definition is in the same translation unit but appears after a function call the initial question which comes to my mind is why we need a function declaration when the function definition is not in the same translation unit or when the function definition is placed right after the function call ?
Anonymous
i know that a function declaration must be there when the function definition is not in the same translation unit or when a function definition is in the same translation unit but appears after a function call the initial question which comes to my mind is why we need a function declaration when the function definition is not in the same translation unit or when the function definition is placed right after the function call ?
That is how the compiler works (or worked - modules change it a bit). When a compiler is compiling a translation unit, it doesn't have information about other translation units. So you help it out by giving the declaration of the function that you intend to call. This declaration is usually in a header file. And the reason why declaration is needed even if the function definition is in the same translation unit but follows the function call is because the lexing and parsing phase of the C++ compiler is from the start to end in one pass (there are exceptions like a class definition is a 2 pass parse and so on) So during the parsing stage, if the compiler sees a token that has not been declared or defined before, it will emit a compiler error. The function declaration prevents this.
Nicky
Please help me to know, i am unable to c programme from base level, can anyone suggest me anything?
Rajesh
How to return strings from c++ to java
?
That is how the compiler works (or worked - modules change it a bit). When a compiler is compiling a translation unit, it doesn't have information about other translation units. So you help it out by giving the declaration of the function that you intend to call. This declaration is usually in a header file. And the reason why declaration is needed even if the function definition is in the same translation unit but follows the function call is because the lexing and parsing phase of the C++ compiler is from the start to end in one pass (there are exceptions like a class definition is a 2 pass parse and so on) So during the parsing stage, if the compiler sees a token that has not been declared or defined before, it will emit a compiler error. The function declaration prevents this.
thats a very great answer thank you very much. so the compiler doesn't have any information about a function call statement to compile it to target specific machine code without the help of a function definition or function declaration ? and the reason why when a function definition appears below a function call the compiler can't compile the function call to machine code is because the compiler process a single translation unit or the source file from top to bottom ? i didn't get what you mean by "module" in the above answer i guess it's the individual function definitions in a C program
?
Module is a new feature in C++20. Look it up
oh well thank you very much. that was helpful 😃
Anonymous
and finally can i know on what resources this information comes from or based on. i did lots of research about this but didn't find the information you gave here
Check out the phases of translation in the C++ standard. The phases 5-8 correspond to compiling and the phase 9 corresponds to linking. This is in a very terse form but. Most of the good books on C++ do have a section on how compilation/linking works when you have source code spread across multiple files.
Anonymous
Thanks any idea about C ?
The process is the same.
Anonymous
#question Hello everyone, I wrote an example for testing mongocxx library I wanna debug my example code and examine some variable of mongocxx and bsoncxx libraries when debugging. but it says: Function boost::optional<mongocxx::v_noabi::result::insert_one>::get has no address, possibly due to compiler optimizations. how can I see value of that in runtime using watch or any other way possible??
?
The process is the same.
ok thank you. i will have to read the translation-phases of the C standard then
Arnold
I don't like C++20, C++ is becoming unnecessarily complicated. They're trying to turn my beloved C++ into compiled Python with all that high level nonsense. No reason to go beyond std::vector.
Arnold
https://en.cppreference.com/w/cpp/language/modules Wikipedia has a decent enough overview Net Miau El Follagatas de la red Man, modules were a terrible idea. Why further bloat the language with something so unnecessary?
Pavel
Should I use any memory order other than relaxed if I don't care about order of operations happening with the atomic, just care that each operation is atomic by itself (e.g. a counter that I want to increment, but not doing any synchronization on this counter value)?
Pavel
And also what memory order should I use if I want to set the value if the new value is bigger? Like this: std::atomic<int> mMax = 0; void setIfBigger(int newValue) { int previous = mMax.load(); while (previous < newValue && !mMax.compare_exchange_weak(previous, newValue)) {} } As I see, I need to provide the memory order for the first load, for the exchange success and failure. My guess that everything should be "relaxed" in my case 🤔. And if I wanted to sync on this variable (setting something before setting the value), then only the success order should be "release", and all others "relaxed"?
Aditya
hello guys....
Aditya
int arrSize = *(&arr + 1) - arr;
Aditya
i am not getting that line of code
Aditya
can anyone explain me...
klimi
and what is arr?
Aditya
that is array of numbers
Aditya
i was looking for the methods of finding length of array....then i found that, but i am not getting that....
Coffee
/get cbook
Unknown
Hello everyone what this means in C because I read a lot and never get the idea ** * Also this one what should do (int **)malloc(sizeof(int *)*SIZE); (int *)malloc(sizeof(int)*SIZE);
klimi
it's about allocating memory and then casting it to some pointer (even though casting is usually implicit)
Pavel
int arrSize = *(&arr + 1) - arr;
This code is really confusing. As I see testing it, when we do &arr we adress the same memory with type of the array (wat?), then we do +1 to shift the point on sizeof(arr), and then doing dereference we transform this address back to array type (wat2?) and subtract the start of the array (get difference between addresses divided by sizeof of array element). WTF
Pavel
What kind of help you need? Have you read the rules, by the way?
klimi
so as input you have 2 coordinates and you need to return bool based on what?
Pavel
on an empty board?
Pavel
then the answer is always true, there's no place on a chess board from which queen can't move
klimi
well then it's just bunch of if... (based on how big the board is etc)
klimi
ah, well, missed it
it's just messy question really...
Anonymous
int arrSize = *(&arr + 1) - arr;
This is Undefined Behavior because you are dereferencing an invalid pointer. So you shouldn't be using code like this. As far as explanation for the code goes, &arr is a pointer to an array. Let us assume arr is an int array of size 3. So &arr will be int (*)[3]. Now &arr+1 will point to an array of 3 integers that is 3*sizeof(int) bytes away from &arr. The invalid operation *(&arr+1) decays to a pointer to the first element of this array i.e. an int* pointer. You subtract arr (which is also an int* pointer) from it. You get 3
klimi
no, i politely decline
Rajesh
How to return std::string from c++ native method
Rajesh
Please anyone tell me
Rajesh
Want to return string from c++ to java
Anonymous
Should I use any memory order other than relaxed if I don't care about order of operations happening with the atomic, just care that each operation is atomic by itself (e.g. a counter that I want to increment, but not doing any synchronization on this counter value)?
Memory ordering is used to order other loads and stores wrt to an atomic load and store. In this case,you only care about the atomic operation on a single atomic variable. So it can just be memory_order_relaxed and everything would work fine.
Anonymous
I don't like C++20, C++ is becoming unnecessarily complicated. They're trying to turn my beloved C++ into compiled Python with all that high level nonsense. No reason to go beyond std::vector.
Well seeing that you have learnt C++ from Indians on YouTube (most of whom are bad and most of whom have never written a single line of professional C++ and just learnt C/C++ as a part of their GATE coaching), i would suggest that you get a 2nd opinion from a decent book on C++20 to understand why Modules are absolutely essential in the evolution of C++ from header files and how it helps improve build times and how it changes code organization. That modules are not yet supported in full by major compilers is a pain in the ass but.
Anonymous
Pavel
With respect to
ah, I thought it's some technical term/abbreviation :D
Anonymous
guys how can i check is there something in string, in C
coal
c with classes
coal
/s
coal
what do you mean with "one statement"
Anonymous
what do you mean with "one statement"
i mean a single statement that works for all c++ programming
coal
i mean a single statement that works for all c++ programming
if you mean statement as in the content between two terminal tokens ";"
Prince Of Persia
Not completely but I would be happy if I be able to help you