Anonymous
No you.
No no u
Yaw
This place needs debugging.
well, I agree but do you have the code for it?
Indolent
No no u
for(int i = 0; i <= 9 billion trillion; i++) cout « No «< " " << YOU!;
Indolent
Take that, kiddo.
Indolent
Useless loop
That loop established democracy in the US.
Indolent
You lost, I won.
ʟᴏɴᴇᴡᴏʟꜰ
🤯
Dima
What the heck, bruh
Dima
You both are losers
Aashirwad
Problem - 272A - Codeforces https://codeforces.com/problemset/problem/272/A
Nils
Hi, how do I get value in std::map by index?
Nils
Nils
.at()
/usr/include/c++/9/bits/stl_map.h:535: candidate function not viable: no known conversion from 'int' to 'const std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>, std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > > >::key_type' (aka 'const std::__cxx11::basic_string<char>') for 1st argument
Anonymous
ouch, thx
you can increment the iterator though
Anonymous
ouch, thx
std::advance, std::next, or a manual loop
Nils
std::advance, std::next, or a manual loop
Solved by rewriting my code so it's a vector with a struct containing filename and fileurl
Nils
Should also avoid undefined behavior
Death Killer
max({max_arr[i-2],arr[i],(max_arr[i-2]+arr[i]),max_arr[i-1]}, comp); Whats wrong
Yaroslav
/get cppbookguide
Nils
Is stuff like 5 * 1000 evaluated during compilation?
Nils
thx
Anonymous
But if you want to force
Anonymous
Use const/constexpr
Nils
alright
Anmol
Is stuff like 5 * 1000 evaluated during compilation?
If it is constexpr or static, yes. Otherwise no
[BLĀNK]
Yo, This is shantanu here
[BLĀNK]
I have some doubts in C, struct pointers to be exact!.
[BLĀNK]
Can someone help me with it?
Asdew
Ask your question.
[BLĀNK]
Okay
[BLĀNK]
struct point { int* a; char b; }; // Initialising struct point* a; // Allocation of memory point* a = (point*)malloc(sizeof(struct point));
[BLĀNK]
The code works great, Its just that we use struct word while initializing, And we don't while allocating memory
[BLĀNK]
Why is that?
[BLĀNK]
😶
ʟᴏɴᴇᴡᴏʟꜰ
Is const preferable or #define...?
Liam
/ban
su
Is const preferable or #define...?
In C, const can warn you or even prevent you from assigning to read-only structures, use of opetations to pointer object, including access and modification structure properties.
su
Why is that?
Becasuse you need actual size of a struct itself, not size of a pointer type
su
The code works great, Its just that we use struct word while initializing, And we don't while allocating memory
And in declaration, struct type pointer is completely defined before initializing *p, so we do not need of explicit struct keyword in declaration of variable *a. Last line of code does initialization, what you called initialization is just a forward declaration, that you will have that variable, can be used in h files, so forward declaration reqires struct keyword, later in code, las line is mus be inside a fuction or a compilation unit, and if it compiles before code above, error will raise
[BLĀNK]
In short, to use a struct we need to allocate memory to it
su
In short, to use a struct we need to allocate memory to it
In C you can use struct without malloc, period. But if you are declaring pointers to it, than you need to initalize it with something.
su
Something in this case is acual allocation with malloc
su
Or you can pass a pointer to a local varable of type struct, as &p, for example
Anonymous
are string literals a pointers..in C
su
are string literals a pointers..in C
what do you mean by string literals. pointers is pointers, strings can be data, pointers, depending of what is defined them, how they passed into where and what is doing around it. you can pass strings as pointers, you can copy them or put on stack. or you can return them as data
su
in asm it is DD
Alex
are string literals a pointers..in C
string literals are stored in memory, so they have memory address which can be assigned to pointer
su
are string literals a pointers..in C
you can add a number to string literal, you can add a number to pointer, but result will be different
su
char c = 'a'; char *ptr_c = &c; a = a + 2; // expect 'c' *ptr = *(ptr + 2); // expect data *ptr to be on a 2 chars to the right
Amir
ptr is the reference to first character of string. Right !
Anonymous
by pointer
passing by pointer and passing by reference are the same right ?
Amir
I mean it points to the address of first char of string
su
+
su
passing by pointer and passing by reference are the same right ?
you can't declare function that will copy arbitrary string literal into function parameters
su
but it works
cam you provide an example? at least it does not copy itself like in C# or int or internal type
Anonymous
cam you provide an example? at least it does not copy itself like in C# or int or internal type
prntStr(char *mystr) printf("%s", mystr); main() prntStr("hello");
Anonymous
copying does not works
then how does it prints the hello
su
this one prints hello
if you change data inside function, it will be available ouside a function
su
then how does it prints the hello
it access it by pointer. it puts pointer to the function stack
Amir
I think he needs to understand printf first
Amir
How does it works for strings
su
/remove that please