Ziky
If you are struggling with with syntax it needs just time and practice
Adeyemo
Ziky do you mind if I message you in DM, I don't want to intrude or go against group rule please
Ziky
Joo
Adeyemo
Adeyemo
I'll do as you say
Adeyemo
Please I do want the project list thanks
Adeyemo
Uliana
Сan you help me with tht task please
1. Create a text file representing a fragment of the C++ program text. There is one operator in each line of text. Replace each assignment statement of the form "variable = variable + number;" to the abbreviated assignment operator of the form "variable += number;". Determine the number of changed operators and write this value as the "number" value in the last changed operator of the assignment of the input text. Display the contents of the input and modified files.
Anonymous
Chat Boss
Ulyana Andreieva sent a code, it has been re-uploaded as a file
Anonymous
Ulyana Andreieva sent a code, it has been re-uploaded as a file
If I have an input line like a=a+1; your logic would fail as you determine pos to be at position of '=' and then search for '+' from pos+3 which is out of bounds.
Your idea seems to be right.
I would suggest reading the line, find just the variable name and the input number which can be found by using rfind for +.
All the code you have now can be used for error handling, like suppose if a line is not in the format expected. But be careful with the bounds.
Once you determine these 2, write the line <var name>+=<num> to output file. And just keep count of how many such replacements are being made.
Uliana
Chat Boss
🏔️ sent a huge message, it has been re-uploaded as a file
hello, do you know what could be the problem in this code? like "memory override" and other stuf..
AlanCcE
🏔️
i don't know but it was in my exam 🥲
Anonymous
Ludovic 'Archivist'
Ludovic 'Archivist'
I never remember where overwriting the stack stands
Ludovic 'Archivist'
Well, anyone can agree that whatever may happen is bad juju
Ludovic 'Archivist'
What would be printed will largely depend of whenever the stack grows upwards or downwards you are probably correct that something will be printed if it grows downwards (even if it is likely to be the entire sentence, not just the start) but on a system where the stack grows upwards, the pointer t is likely to get corrupted and cause a bad memory access
Anonymous
Is it not implementation defined behaviour while writing in the struct and unspecified behaviour afterwards?
It is Undefined Behavior.
He is copying the string "what could go wrong" into an array of length 5.
This is what the C standard says wrt to your question on writing into the strict:
An array subscript is out of range, even if an object is apparently accessible with the given subscript (as in the lvalue expression a[1][7] given the declaration int a[4][5]) (6.5.6).
So even if we were to assume that he was writing only a string of length 9 into a and this overflows into b, it is still Undefined Behavior.
Kay
Guys know how to create the if statement that counts the letters from the file txt?
Ziky
Ludovic 'Archivist'
Ludovic 'Archivist'
And decayed arrays are not required to behave like arrays as they are decayed
Ludovic 'Archivist'
But access beyond them here is basically implementation defined (because the struct layout is implementation defined) but beyond the scope of the struct, we may be modifying stack memory which I think is either undefined behaviour or unspecified behaviour
Ludovic 'Archivist'
That is where my doubt is coming from
ƙáñɧíყá
Helloo
ƙáñɧíყá
Can i ask a Linked list question...i am not able to encode it in Dev C....
Minh
I have double variables x = 10000000, how to display 10000000 instead 1e+07 in c++
Ziky
cout << static_cast<int>(x)
Ziky
Maybe 😁
Minh
Thank you i used cout.precision()
Ziky
Welcome, definitely better solution than casting
Anonymous
🙃🙃Hello everyone, I have a question regarding memory allocation. Well when we declare a variable and associate it to a data type we are reserving a space in memory so far so good. Depending on the architecture, the storage size can vary, for example, type “int” in 32bits, its size is 2bytes and 4bytes in 64bits. If I have architecture for 64bits int value = 132255; Will the variable have allocated four addresses where each address will store 4 bytes? Or In just one address will it store the entire value? The other question associated with this is the concept of data type is it related to a set of numbers available in the type? or in the amount of bytes it can store and when stored it breaks into parts according to the amount of bytes? In this case, when 132255 is stored, it will be placed in an address or divided into four because the int type for 64 bits has 4 bytes.
Pavel
🙃🙃Hello everyone, I have a question regarding memory allocation. Well when we declare a variable and associate it to a data type we are reserving a space in memory so far so good. Depending on the architecture, the storage size can vary, for example, type “int” in 32bits, its size is 2bytes and 4bytes in 64bits. If I have architecture for 64bits int value = 132255; Will the variable have allocated four addresses where each address will store 4 bytes? Or In just one address will it store the entire value? The other question associated with this is the concept of data type is it related to a set of numbers available in the type? or in the amount of bytes it can store and when stored it breaks into parts according to the amount of bytes? In this case, when 132255 is stored, it will be placed in an address or divided into four because the int type for 64 bits has 4 bytes.
First question, it will be one address, it will point to the start of the memory that was allocated, and since the size of the type is known to the compiler it can handle reading from that memory correctly when you dereference the pointer.
The second question I don't really understand, are you talking about C or C++? because concept of data types differs between the languages
Anonymous
/
Hi i am trying to understand when should i use the restrict keyword
Anonymous
Ziky
Ziky
Ziky
you are telling the two memory regions are not overlaping
Pavel
C++
Every data type has known to a compiler size, if you compile to a platform where int is 4 bytes, then the compiler knows that int is always 4 bytes, so it knows how much data to allocate and how to address it.
In general for a variable of any type to be used correctly:
1. Memory for it should be allocated
2. Constructor should be called on that memory.
When you call new it does both for you. If you create a variable on the stack, then both will also be resolved automatically (memory on the stack will be prepared for your variable and constructor called when needed).
Even if the constructor doesn't do anything (and there's no actual call happens under the hood) formally this rule is true.
Anonymous
The thing is, no array subscript is actually used here, only pointers to characters
Struct layout in the case of consecutive arrays of char requires no padding bits between the arrays. Two consecutive char arrays will be stored consecutively. So a and b in the struct will be stored consecutively here. Moreover for a struct of char arrays no sane implementation will allocate padding bits before or after the arrays (this is what is implementation defined behavior according to you). On all implementations, the size of this struct would be 9. This is not guaranteed by the standard but this is what it will be.
Now writing beyond allocated memory irrespective of whether you do it via a pointer or through the array directly is Undefined Behavior and not Unspecified Behavior.
Razan
im new to vs code and its telling me
Cannot build and debug because the active file is not a C or C++ source file.
and
Unable to find cl.exe. C/C++: cl.exe build active file task is ignored.
i did follow a video to download a debugger and compiler but it dosent work
do you know how to fix this?
/
Help i have a problerm
/
i am trying to decompile an assembly code into c++
/
and i have a problem with the data type
/
LDR R0, [R0,#PluginContext.field_14]
LDR R0, [R0, #4]
LDR R0, [R0]
LDRB R3, [R0, #7]
/
/
/
i think its something like a char *** because
LDR R0, [R0,#PluginContext.field_14] : char ***
LDR R0, [R0, #4] : char **
LDR R0, [R0] : char *
LDRB R3, [R0, #7] : char
Ludovic 'Archivist'
Anonymous
Anonymous
But this is allocated memory, as it is the stack itself, I do not know how unregulated access of the stack is defined in the standard
The standard doesn't talk about the heap or the stack. It is possible for a C implementation to support function calls through a stackless environment (whether there exists such an implementation is beyond me however). The same is true for coroutines (C++ does necessitate stackless coroutines in a way but compilers do support those cases where they are able to determine the lifetime entirely on a stack). The standard doesn't mention stack explicitly anywhere. The only thing it mentions is that out of bound access is Undefined Behavior irrespective of whether the implementation uses alloca calls or malloc/sbrk calls.
Olivia
int n;
int **arr= new int *[n]
What does it means
𝔖𝔞𝔯𝔬
Guys when you declare a pointer this way
Int arr[20]
If you do this in a function it allocates in the heap or in the stack
Danya🔥
Danya🔥
There is neither heap nor stack in C or C++
Duhi lucu| NO SPAM
hello its great to be here
Duhi lucu| NO SPAM
i have been looking for something like this
Ya deway
Hi im learning C whats this declaration mean/do?
hexstr = (char *) malloc(size*BYTE_MULT);
I know that * Is used for pointer declaration but only (Char *) what do?
Thanks for any help
Danya🔥
Ya deway
Hexstr = Is not a declaration?
Danya🔥
Danya🔥
Hi im learning C whats this declaration mean/do?
hexstr = (char *) malloc(size*BYTE_MULT);
I know that * Is used for pointer declaration but only (Char *) what do?
Thanks for any help
This line of code is using the malloc() function to dynamically allocate memory in C.
In this particular case, hexstr is being assigned a pointer to the memory block that malloc() allocates. The (char *) is a type cast which tells the compiler to treat the pointer returned by malloc() as a char pointer. This is because malloc() returns a pointer of type void *, which can be cast to any other pointer type.
size and BYTE_MULT are variables that are being multiplied together to determine the size of the memory block to allocate. Once the memory has been allocated, hexstr can be used as a pointer to an array of char values that has a size of size * BYTE_MULT.
It's worth noting that when you allocate memory using malloc(), you are responsible for freeing it when you're done using it. This is typically done using the free() function.
Danya🔥
We need ChatGPT here..
Ya deway
Ya deway
AlanCcE
https://github.com/Anthhon/cSnakeGame