Prince Of Persia
Pavel
O.o
Thanks
There are more differences by the way, not every C code can be compiled with C++ compiler
Prince Of Persia
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
Prince Of Persia
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
Anonymous
Ahn
Which one do you recommend to start guys, c or c++?
Anonymous
Ahn
Prince Of Persia
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
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
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
Instead for the closing function, how should I call it?
Stefano
FILE * closeFile(FILE * fp) {
if (fp != NULL)
fclose(fp);
return NULL;
}
Vlad
Vlad
Just call one over the other
Stefano
Vlad
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
Vlad
Anonymous
Thierry
Tell me more
Stanislav
Vlad
Tell me more
What more? You didn't say what are you going to do
Anonymous
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
Anonymous
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🙈😍🙌
Davi
Anonymous
Anonymous
https://github.com/alandefreitas/matplotplusplus
This is better
Xudoyberdi
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
AHMED
Anonymous
Xudoyberdi
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
Sasuke
Xudoyberdi
Sasuke
MRT
std::string *getName(const string& attribute_name) const {
if(condition)return &attributes[i];
return nullptr;
}
Anonymous
MRT
Anonymous
A pointer to std::string.. what a nonsense
Anonymous
MRT
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
MRT
Anonymous