Leovan
they are important
didnt know about that, interesting
coal
didnt know about that, interesting
they're more important when linking libraries
coal
because some libraries might depend in the other
coal
so linking is done right to left in order of importance, where right-most libraries dont depend in anything
coal
yw
coal
if you're under linux you can prepend a shebang specifying the interpreter for the contents of the file
coal
if you're under windows you cant unless you directly or indirectly run it using the correct interpreter
coal
if you mean an actual executable file then you need to know how to write compilers
M
/getcbook
lion
Hi Guys, Good morning, I am just beginning to learn C programming language since last week. Can anyone say something that which timeframe should i allocate for a day. Between i really interesting on learning void main () now which i have been focussing from scratch?
lion
Any suggestions/comments would be very welcome and appreciated
Vala
C# Login error dt
%Nikita
Macros work before C/C++ compiler is even involved, they don't check a lot of things that related to the language and can break logic of your program. imagine you have a macro function like #define SQR(x) (x)*(x) Then you can call it like this int i = SQR(++a); or int i = SQR(heavyFunctionCall()); (hope you see how it goes wrong) inline is working on the language level so it is much safer and in most cases more readable and easy to work with. However inline doesn't guarantee that the function will be inlined (either it can be not possible in some cases, or compiler will decide that inlining of this function will not improve the performance). There are compiler-specific ways to force-inline functions if you really want to ensure it will be inlined
Thank you! I remember your SQR macro from “C programming language”. There was the same macro: #define SQR(x) (x)*(x) Yes, I understood but I have read somewhere that inline keyword has some linked meaning, hasn’t it? Or it only tells compiler to paste code if it can. I didn’t notice any problem with: > int i = SQR(heavyFunctionCall()); It will be replaced by: int i = (heavyFunctionCall()) * (heavyFunctionCall()); What’s problem? Won’t work only if functions have static variables in it or something like that: #define SQR(x) (x)*(x) long heavyFunctionCall(void){ return 5; } long i = SQR(heavyFunctionCall()); In the end of this part i will store 25. What’s wrong in second situation you described? With first I already understood: (++a)*(++a) - a will incremented two times. But with function it is all OK
alice
program that asks the user to enter the parameter 1 tand an upper limit of the stochastic variableXwhich the probability is to be calculated for, and which draws the Poisson distribution based on this information. Run the program with a number of different values for At, and notice how the Poisson distribution begins to resemble a normal distribution when the value of the parameter Aincreases.
alice
please need help
.
Can some one help how to decript Ransom ware virus!!?
klimi
Can some one help how to decript Ransom ware virus!!?
do you know what cipher and key was used?
MᏫᎻᎯᎷᎷᎬᎠ
.
.
.cuag
.
Online encrypted
klimi
i see, you are not trying to code decryptor :D
.
I am beginner 1st year so can u help me plzz?
Anonymous
I am begginer if C++ What shall I do
Anonymous
.
I have decripted local disk c and cant decript d and e
Rojal
Any one can help me to decrypt .BOOA
Pritam
Hi
Pritam
Anyone interested in online Coding Cotest?
Shahrukh
I am begginer if C++ What shall I do
Watch code with Harry on YouTube and practice
Azhar
cout << carObj1.brand << " " << carObj1.model << " " << carObj1.year << "\n";   cout << carObj2.brand << " " << carObj2.model << " " << carObj2.year << "\n"; I want to reduce code, want to print two object with single line of code ...how can i ?
coal
if you google a bit, you'll find something like this: https://www.geeksforgeeks.org/overloading-stream-insertion-operators-c/amp/
Azhar
overload << and provide your own implementation which allows you to print both attributes directly using std::cout << carObj;
Like everything will be printed by std::cout<<carobj1 Std::cout<<carobj2 Or i have to call each class again?
coal
but you'll save the need to print model and year individually
coal
you'll just std::cout << carObj and done
coal
if you want to print both objects, just do: std::cout << carObj1 << std::endl; std::cout << carObj2 << std::endl;
Arnold
you need to define what the << operator will do for the class
Arnold
operator overloading
Arnold
but don't bother, it's not too much code...
Anonymous
include<iostream> using namespace std; class Complex { private: int real, imag; public: Complex(int r = 0, int i = 0) {real = r; imag = i;} // This is automatically called when '+' is used with // between two Complex objects Complex operator + (Complex const &obj) { Complex res; res.real = real + obj.real; res.imag = imag + obj.imag; return res; } void print() { cout << real << " + i" << imag << '\n'; } }; int main() { Complex c1(10, 5), c2(2, 4); Complex c3 = c1 + c2; c3.print(); }
Anonymous
Please please
Pavel
Every time when I write above code I get confusion Can anyone describe This code only from above code Complex operator + (Complex const &obj) { Complex res; res.real = real + obj.real; res.imag = imag + obj.imag; return res; }
This is operator overloading syntax This code allows the class to use operator + that returns a new object. So let's say we have two objects of class Complex named a and b. When you do Complex c = a + b; This operator will be called on object a, b passed as an argument, and the result will be assigned to c. As far as I remember you can also write it as Complex c = a.operator +(b); which should be the same thing
Harleen
Hello, I am trying to compile the code but I don't understand what is wrong. I am using Windows subsystem for linux. gcc ‑‑std=c++11 task1.cpp cat.cpp ‑lstdc++ ‑o task1 ERROR: gcc: error: ‑‑std=c++11: No such file or directory gcc: error: ‑lstdc++: No such file or directory gcc: error: ‑o: No such file or directory gcc: error: task1: No such file or directory
\Device\NUL
Also, the correct parameter is -std=c++11 , but i prefer using -pedantic
Azhar
Constructor will help you
I have knowledge of constructor but is it possible to copy class and print with multiple objects without calling each time , like we do in daily life?
Azhar
but don't bother, it's not too much code...
Im learning how to print multiple object without calling class each time
Krishnaa
vector<int> x; vector <int> preorder(Node* temp) { vector<int> p; if(temp==NULL) return p; x.push_back(temp->data); preorder(temp->left); preorder(temp->right); return x; // Your code here }
Krishnaa
Why this code snippet doesn't work for PreOrder Traversal in GFG practice???????
Ravi
Why this code snippet doesn't work for PreOrder Traversal in GFG practice???????
Your code will be fail during backtracking when temp==NULL ..... This GFG problem is not for recursive approach you have to go with iteration approach and if you want to go with recursion then this will help u out.... void preOrder(Node* root,vector <int> &v) { if(root != NULL) { v.push_back(root->data); preOrder(root->left,v); preOrder(root->right,v); } } vector <int> preorder(Node* root) { // Your code here vector <int> res; preOrder(root,res); return res; }
Distac_221
hello, can you guys help me to improve this code, and whats your suggestion with this code https://pastebin.com/L0rSddE9
klimi
hello, can you guys help me to improve this code, and whats your suggestion with this code https://pastebin.com/L0rSddE9
- you are missing check if malloc was successful. - you don't need to explicitly cast it to (char*) - comments like "// yes I want to learn ..." are irrelevant to the code - comments on "print ... Hello ..." that only says // print your name is just unnecessary ( same with input your name/ malloc, or even the #define macro)
klimi
Also when someone enters longer name, the newline character won't be print
Distac_221
Also when someone enters longer name, the newline character won't be print
about that, i just dont want someone to type long name, maybe if its need full name i will increase it
klimi
You could fix this by reading the return value of fgets and setting newline on your own, or have some check if more data is coming
klimi
about that, i just dont want someone to type long name, maybe if its need full name i will increase it
then just make a check and if user tries to input longer, just say that "too long name" or something...
klimi
https://en.cppreference.com/w/c/io/fgets
klimi
well that is on your how you choose to implement it
klimi
you could just forcefully put the str[n-2] to a newline character
klimi
but that could not work all the time
klimi
it would be better to think what cases can occur and how to deal with them
Distac_221
thank you
klimi
no problem
Distac_221
no problem
i was just try to ask if someone doesn't input anything how do i give the message
klimi
i was just try to ask if someone doesn't input anything how do i give the message
Well you could check how many characters have been written
Distac_221
why its always give "please input your name" even if i gave input https://pastebin.com/asz0rrp9
Distac_221
your if statement should be if(strlen(str)==0)
what is the difference between = and ==?