Pavel
O.o Thanks
There are more differences by the way, not every C code can be compiled with C++ compiler
Anonymous
Is there any difference between C and C++ (same code)
Yes Some code from one language may not be compiled in other one
Prince Of Persia
But when I was compile main.c file by G++ Then I decompiled by some apps The app said it's a C program not a C++ program
Pavel
In syntax?
In features, C and C++ diverged long time ago and developed separately. E.g. C++ doesn't have variable length arrays (some C++ compilers can support is as an extension but it's not portable), also designated initializers arent available before C++20 but available in C.
Prince Of Persia
Thank you a lot
Prince Of Persia
But the last question Why C++ does not support of good futures that C have?
Ahn
Which one do you recommend to start guys, c or c++?
Ahn
C++
Tnx
Prince Of Persia
Which one do you recommend to start guys, c or c++?
I started by C++ But it's hard for beginners
Vlad
But the last question Why C++ does not support of good futures that C have?
Because it used ANSI C by the means of compatibility. Then the languages split in their development
Stefano
Hi guys, when I call this function, how can I use the value it returns?
Stefano
FILE * openFile(char *nameFile, char *mode){ FILE *fp = fopen(nameFile, mode); if(fp == NULL) exit(-1); return fp; }
Vlad
Hi guys, when I call this function, how can I use the value it returns?
FILE* f = openFile("asdf.txt", "r");
Vlad
Although I dunno why it exists tbh
Vlad
Shouldn't you be able to handle the situation when a file doesn't exist?
MRT
😂
Mar!o
Char: 8 bits Int: 16 (when specified) or 32 Float: 32 Double: 64 Long double: 96
long double is 80 bits wide not 96 on the most platforms
Box of
Char: 8 bits Int: 16 (when specified) or 32 Float: 32 Double: 64 Long double: 96
And int is usually 32 but to be exact it isn't really specified like that. Char defines word - usually it's 8 bit but it can be anything, int is defined as something bigger than short and smaller than long and similarly with float and double About floats it's usually defined by IEEE754 and looking at standard you have 256 bit version of float, so you need to look at specific implementation
Stefano
Shouldn't you be able to handle the situation when a file doesn't exist?
I am completing a project and I need to use the functions that are already present.
Stefano
Instead for the closing function, how should I call it?
Stefano
FILE * closeFile(FILE * fp) { if (fp != NULL) fclose(fp); return NULL; }
Vlad
Instead for the closing function, how should I call it?
Lol they are literally with same signature
Vlad
Just call one over the other
Vlad
Second day in C? :P
Stefano
Thierry
What graphics library does one recommend for C(99) and what are it's strengths/weaknesses? Maybe someone could point me in the right direction
Thierry
Tell me more
Vlad
Tell me more
What more? You didn't say what are you going to do
Anonymous
why not?
Because it's poorly designed language that encourages bad practices
Anonymous
Well, thank this "poorly designed language" for having a computer nowadays lol
Thierry
Use case?
I want to learn some more C and do essentially a 2d plot which changes over time.
Anonymous
I appreciate your advise on choosing a programming language as a beginner
Anonymous
Thank you all🙈😍🙌
Igor🇺🇦
I want to learn some more C and do essentially a 2d plot which changes over time.
Consider using something like this https://matplotlib-cpp.readthedocs.io/en/latest/. It's a cpp wrapper of python library.
Anonymous
https://github.com/alandefreitas/matplotplusplus This is better
Davi
I want to learn some more C and do essentially a 2d plot which changes over time.
If you don't need to update the plot often, maybe using C to generate a gnuplot script will be sufficient.
AHMED
#include <iostream> using namespace std; class triangle { public: int side1, side2, side3, perimeter; void setSides(int a, int b, int c) { side1 = a; side2 = b; side3 = c; } int getPerimeter() { perimeter = side1 + side2 + side3; } }; int main() { triangle obj; obj.setSides(1, 2, 3); cout << obj.getPerimeter(); return 0; }
AHMED
Why the output is 127 instead of 6?
AHMED
The next program displays a different number each time I run it. Why?
AHMED
#include <iostream> using namespace std; class triangle { public: int side1, side2, side3, perimeter; void setSides(int a, int b, int c) { side1 = a; side2 = b; side3 = c; } int getPerimeter() { perimeter = side1 + side2 + side3; } }; int main() { triangle *ptr= new triangle; (*ptr).setSides(1, 2, 3); cout << (*ptr).getPerimeter(); return 0; }
Anonymous
#include <iostream> using namespace std; class triangle { public: int side1, side2, side3, perimeter; void setSides(int a, int b, int c) { side1 = a; side2 = b; side3 = c; } int getPerimeter() { perimeter = side1 + side2 + side3; return perimeter; } }; int main() { triangle obj; obj.setSides(1, 2, 3); cout << obj.getPerimeter(); return 0; }
Anonymous
Bro write return parameter statement inside class getParameter() member function
Xudoyberdi
And what will you do with an arbitrary pointer that user inputed?
https://pastebin.com/rAGiVWY0 I guess I'm fine now...
Sasuke
Int main(){ int a=5, b=0; b = ++a + ++a; printf("%d\n", b); } Why 2 different compilers output different results? 13 and 14?
Vlad
Why is that so?
Order of execution is not guaranteed
MRT
std::string *getName(const string& attribute_name) const { if(condition)return &attributes[i]; return nullptr; }
Anonymous
A pointer to std::string.. what a nonsense
Anonymous
why ?
Because no one writes code like this
Anonymous
It's bad
MRT
It's bad
What should be the correct method of return string ??
Anonymous
Pointers should not be used as optional type
Anonymous
What should be the correct method of return string ??
In this case std::optional<std::string>
Anonymous