Vlad
It is of size of a single pointer
Vlad
4 or 8 bytes
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Ok thanks, I know it was a silly question, but I wanted to be sure. Thank you very much!!
Vlad
It would be a good idea to store that size somewhere
Leovan
glm is header only, just distribute it alongside
Is it good idea? Size of glm is 20 mb, when all my project size is 1 mb. And anyway i want to know what to do when i deal with library.
Dhruvan
Anyone knows the socket programming.
klimi
Anyone knows the socket programming.
don't ask meta questions
$ameer
Hi pIs help me want to print order of number like if user enter 1 , have to print 1st, I try by replacing with array elements but it has limitation like if I save array till 100 and user entered 101...
$ameer
How can you please guide me should I have to add dynamically during runtime?
Vlad
How can you please guide me should I have to add dynamically during runtime?
https://en.cppreference.com/w/cpp/container/vector/push_back
Natanim
How many times does the initialization of a NESTED for loop execute?
David Anthony
Hello am new
Michel
How can I implement a constructor that makes some kind of list interpretation? Something like: MyClass foo = {0, 1, 2, 3, 4, 5}; // with an arbitrary number of elements or not
Michel
std::initializer_list
Is there any other way?
Danya🔥
No it's not better
Danya🔥
Why do you even need to allocate a vector?
Danya🔥
It's not an answer to my question
Ehsan
internally all the data are allocated using the "New" operator, so you don't get any benefit from allocating the vector in the heap.
Danya🔥
NO
Ehsan
Lol no
Ehsan
Yeah you can use whatever you want
Ehsan
ok when the function ends the vector class will call its destructor so you don't need to worry about that :)
Ehsan
just use the clear() method
Ehsan
https://www.cplusplus.com/reference/vector/vector/clear/
Ольга
Hello! Maybe this is a stupid question, but why do I have one correct conclusion and another time with the same code and data not? Is this something missing somewhere?
Pavel
Hello! Maybe this is a stupid question, but why do I have one correct conclusion and another time with the same code and data not? Is this something missing somewhere?
What is "conclusion" in this context? Can you share your code (use pastebin) and describe what is the input, what is the results you're getting, and what result you expect to get
Nobody🪲
#include<stdio.h> int main() { int a,b,c,d,e,percentage; printf("enter the numbers:"); scanf("%d %d %d %d %d",&a,&b,&c,&d,&e); percentage=(a+b+c+d+e)*100/500; (percentage<=60? printf("first division"):(percentage>=50?printf("second division"):(percentage>=40 ? printf("third division"):printf("fail")))); return 0; }
Nobody🪲
Yes
Nobody🪲
To determine average result
Nobody🪲
I want to solve it with conditional operator
Nobody🪲
Not with the logical
Nobody🪲
Cant understand
Nobody🪲
Can u explain a little bit please?
Nobody🪲
Oh thanks
Nobody🪲
I got it thank u so much
Nobody🪲
But which will be more efficient for this question? To solve with logical operator or conditional operator
Nobody🪲
Thanks u
\Device\NUL
But which will be more efficient for this question? To solve with logical operator or conditional operator
It just syntatix sugar and readabililty to me, but nested ternary is stupid
\Device\NUL
Here some example of right use of ternary puts( yes ? "Yes" : "No")
Ольга
Hi to all. Another stupid question, how to properly clear the array of pointers that is not just free [arr]? I found something like arr [i] == NULL but I'm not sure. So is it right to clear the indicators or not?
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi to all. Another stupid question, how to properly clear the array of pointers that is not just free [arr]? I found something like arr [i] == NULL but I'm not sure. So is it right to clear the indicators or not?
I'm a beginner and I think this is an interesting question. From what I understood in my Compure Architecture course so far, if you do something like char *vector[64], then you are allocating on the stack a vector of 64 pointers to char, then you should not clear it. On the other hand, each entry in the vector is a pointer to a type of data that you do not know at compile time (let's imagine you want to assign the 7th entry of the vector to a string taken from an I/O operation) therefore I think that in this case the pointers in the array point to data in the heap. But, again, I'm just a beginner. I would not empty the vector, but I may be wrong. Writing this only to confront with more expert people so they can tell me what's wrong with wat I've said
\Device\NUL
in C NULL is 0 casting-ed tovoid *
Larbi
Hello I’m looking for a website or a book to learn OOP in C++, any recommendations!?
Larbi
Thank u so much
Anonymous
It just syntatix sugar and readabililty to me, but nested ternary is stupid
Ternary operator is not syntactic sugar. It is infact an expression unlike the if statement. So ternary operator expression has a value unlike the if statement which makes it very useful in functional programming. Unlike languages like Rust where if, for and while are all expressions, in C++ they are statements. The designers of the language (C) felt the need for an if expression which is the reason behind the ternary operator. So it is not syntactic sugar.
محمد
I need help solving a question
Ольга
int arr = (int)malloc(r * sizeof(int*)); for (i = 0; i < r; i++) arr[i] = (int*)malloc(c * sizeof(int*)) I will create an array in this way, ie with pointers and the array itself, the array itself can be released, if I'm not mistaken with the function free (array name), but how to be with pointers, I do not understand. Is it enough to write something like free (array name [i])?
محمد
1. Practice composition of objects 2. Practice operator overloading Project details You will write a PlayList class that manages a play list of songs. The PlayList class manages a dynamically allocated array of song objects. The song class is provided for you in song.h and song.cpp, which should NOT be modified. Your playlist class will be implemented in two files playlist.h and playlist.cpp. The class will support two basic functions: 1. Managing the playlist. This includes adding songs. 2. Playing from the play list. This includes keeping track of which is the next song to be played. Obviously we will not actually be playing any music. “Playing” the song will consist of printing the name. To support these functions, your PlayList class should have the following public member functions: • Your class should have the following private data member: Array of songs object, integer member to record the capacity of the dynamic array (array size), an integer member to record the number of songs in the dynamic array, and an integer member to record the current song index (to support the play function). • The class should have a parametrized constructor that builds an empty playlist based on size specified by the user. • void AddSong(const Song &s); This function will add s to the end of the play list if your list is not full. Otherwise, your list will not change if it is full. • void ShowAll() const; This function will print all of the songs in the play list on the screen. • void play(int num=1); This function “plays” num songs from the list. The songs in the list should be play in a circular manner: when reaching the end of the list, repeat from the beginning. • void ShowStatus() const; This function shows the status information of the playlist including the total array size, the number of songs in the list, and the current song index. • The class should have a destructor that deletes the memory allocated for the playlist when the PlayList object is deallocated. The PlayList class must also overload the following operators and implement the described functionality accordingly: 1. Addition operator (+): adding a song to a playlist (i.e. playlist object + song object) This method will update the playlist object by adding the new song at the end (same as the result of AddSong). All data members in this class should be private. To support the public and friend functions, the PlayList must maintain a number of data members.
klimi
1. Practice composition of objects 2. Practice operator overloading Project details You will write a PlayList class that manages a play list of songs. The PlayList class manages a dynamically allocated array of song objects. The song class is provided for you in song.h and song.cpp, which should NOT be modified. Your playlist class will be implemented in two files playlist.h and playlist.cpp. The class will support two basic functions: 1. Managing the playlist. This includes adding songs. 2. Playing from the play list. This includes keeping track of which is the next song to be played. Obviously we will not actually be playing any music. “Playing” the song will consist of printing the name. To support these functions, your PlayList class should have the following public member functions: • Your class should have the following private data member: Array of songs object, integer member to record the capacity of the dynamic array (array size), an integer member to record the number of songs in the dynamic array, and an integer member to record the current song index (to support the play function). • The class should have a parametrized constructor that builds an empty playlist based on size specified by the user. • void AddSong(const Song &s); This function will add s to the end of the play list if your list is not full. Otherwise, your list will not change if it is full. • void ShowAll() const; This function will print all of the songs in the play list on the screen. • void play(int num=1); This function “plays” num songs from the list. The songs in the list should be play in a circular manner: when reaching the end of the list, repeat from the beginning. • void ShowStatus() const; This function shows the status information of the playlist including the total array size, the number of songs in the list, and the current song index. • The class should have a destructor that deletes the memory allocated for the playlist when the PlayList object is deallocated. The PlayList class must also overload the following operators and implement the described functionality accordingly: 1. Addition operator (+): adding a song to a playlist (i.e. playlist object + song object) This method will update the playlist object by adding the new song at the end (same as the result of AddSong). All data members in this class should be private. To support the public and friend functions, the PlayList must maintain a number of data members.
and what do you need help with?
\Device\NUL
int size is not portable and you must use int *. For example in windows that using data model llp64, int size is 32 while the pointer size is 64 bit. You might get overflow due int can't hold 64 bit value
klimi
محمد
You can help me?
Ольга
NOOO, don't use int use int *
int arr = ( int ) malloc(r * sizeof(int*)); for (i = 0; i < r; i++) arr[i] = (int*)malloc(c * sizeof(int)); Oh I'm sorry when inserting the code for some reason this tape was edited. Something like this will be better?
\Device\NUL
Ahh, maybe your compiler didn't warn you due to integer casting
klimi
You can help me?
Yes but... What do you need help with?
Nobody🪲
#include<stdio.h> int main() { int age; char sex,ms; printf("enter age,sex,ms"); scanf("%d %c %c",&age,&sex,&ms); if((ms=='M')||(ms=='U'&&sex=='M'&&age>30)||(ms=='U'&&sex=='F'&&age>25)) printf("the driver should be ensured"); else printf("the driver should not be ensured"); return 0; }
klimi
*cus*
pardon?
Nobody🪲
I want to solve this with conditional operation..i have tried bt not running anybody can help me out?
Vlad
pardon?
Because telegram interprets it as a bold text or smth
Nobody🪲
#include<stdio.h> int main() { int age; char ms,sex; printf("enter age ,ms,sex:\n"); scanf("%d %c %c",&age,&ms,&sex); (ms=='M'?printf("ENSURED"):(ms=='U'&&sex=='M'&&age>30||sex='F'&&age>25?printf("ensured"):printf("unendured"))); return 0; }
Vlad
And asterisk is gone