Pavel
Ok
Ah right, you also need to zero j in the outer loop before doing the inner loop
Pavel
Ok
Here's your code with these two changes (and formatted)
https://ideone.com/5Wszdi
Pavel
That's why it better to use for loops instead of while in such cases, more difficult to forget such things and looks better
Anonymous
%Nikita
Hi guys!
I have problem with reading these loops:
int h = 125;
while (h > 0) h—;
How many times will it repeat? What about that:
int h = 125;
while (h— > 0) ;
And that:
int h = 125;
while (—h > 0) h;
And that:
int h = 125;
while (—h >= 0) h—;
Am I stupid, or there is some trick to read it and predict how many times it will repeat? C is a simple language, “you get what you write”, but why I don’t understand what will I have in situations I described. Pls can you give me some advice
%Nikita
'''''''
%Nikita
%Nikita
Then u don't need any trick
Ok, for example this:
h = 125;
while (—h > 0) —h;
How many times will repeat this loop? I literally don’t understand how to predict it without compilation
'''''''
--h>0 or --h>=0?
%Nikita
%Nikita
- - h > 0 in condition
'''''''
So, in every iteration of the loop, the value of h reduces by 2, so as h equals 25, u've had 50 iterations, and again when h=1, u've had 12 more iterations, then --h gives 0 which isn't>0 so, u've 62 iterations of the loop
'''''''
If u consider --h>=0 as in your original question, u've 63 iterations as there's an additional iteration after h=1( --h equals 0 and so an extra iteration)
%Nikita
So, in every iteration of the loop, the value of h reduces by 2, so as h equals 25, u've had 50 iterations, and again when h=1, u've had 12 more iterations, then --h gives 0 which isn't>0 so, u've 62 iterations of the loop
Ok, I think I understood this, but I will think about it. How many years have you been practicing?
'''''''
'''''''
In the last year I've learnt basics of Python and C
%Nikita
Arta
Strife
coal
Shrivatsa
Hey, I am a beginner in C
I had written program of calculating total marks, but the Output of total marks in value is showing large no in negative ex: Totalmarks:-9036284, Totalmarls:-3768992
Shrivatsa
How should I correct it
Edgelord
Ed
Hello. I wanted to use a function pointer within one class and use it to reference a member function in another class.
void Processor::on_complete(void (*func)(CentralUnit<Processor>& cpu, Processor& core))
{
f = &(this->m_host->complete_job(this));
}
how can I link the function pointer to a member function within the class Central Unit?
Ed
the class Processor has a function pointer as a private data member.
Nitesh
hi, is it possible to take input from user and make it constant ?
Anonymous
Hey guys i just wanted to know whether there is any pro coder in C ?
Arta
klimi
Strife
good,gams👌
When I wanted to choose a language to learn, Someone suggested me C#, because you can build graphic software from scratch.
But I had no interest in it
I was strangely in love with C++, then he told me: In C++ you go back to the DOS environment, boring and harsh, but it was strangely sweet to me, although after a few months of programming, I was very disappointed😂 And I quit programming for two years, but now I'm on my way back to C++😄
where are you from?🤔
Honestly, like you, I'm particularly interested in C ++ I do not know why, we have simpler languages but C ++ is fun for me and I use sfml to make the game, working with sfml is like Dark Souls game Hard but enjoyable. I'm from Iran
Anonymous
How I can remember how to programming if I do not program for a while.
Anonymous
I got busy with university
Arta
Arta
Arta
No Name
hey,
i'm trying to loop over a user input using while loop (the input is for example "1 2 3 4 5")
i want to append the integers into array, how do i do it ? this is what i wrote so far.. but something is obviously wrong with it
printf("\nInsert the first vector : \n");
while (scanf(" %d", u)==1)
{
scanf("%d", u[i]);
}
Anonymous
klimi
coal
coal
unless it has a string-like format code, in that case it must take whitespace in account
coal
coal
if you want to make it dynamic so you dont have to input a size you can use fgets and strtok, but it will be a little harder
Abhishek
why can't we use float main() in a c program?
Leovan
Abhishek
For what
i was using float main() for calling my main function but my ide showed warning
Leovan
Abhishek
UrCodeBuddy️ 💻
does this make sense? what i want is to set a default value when i call my function
int function(int a, int b, int c=0){
statements
}
UrCodeBuddy️ 💻
i want to say that, if there is no value input for c, it should by default be 0
Anonymous
Leovan
why is it so?
because all programs should return int value (return code) which means how program was end. 0 - all okey, != 0 - error
UrCodeBuddy️ 💻
Abhishek
coal
coal
also you shouldnt
Abhishek
Anonymous
I am learning this program for one week ago
%Nikita
I confused about this:
inline void f(void) { printf(“I am inline func\n”); }
#define f2(…) printf(“I am macro\n”);
As I read on forums the meaning of inline keyword is that it’s used for telling compiler to paste function code into place where it was called. But macro do the same, only one difference I saw - macro code pasted by preprocessor, and inline function pasted by compiler. Then - what difference between these two, can someone explain better pls.
coal
I confused about this:
inline void f(void) { printf(“I am inline func\n”); }
#define f2(…) printf(“I am macro\n”);
As I read on forums the meaning of inline keyword is that it’s used for telling compiler to paste function code into place where it was called. But macro do the same, only one difference I saw - macro code pasted by preprocessor, and inline function pasted by compiler. Then - what difference between these two, can someone explain better pls.
inline keyword makes a request to the compiler to embed the instructions within the function at the place of the call, which removes function call overhead in cases where it's just not worth it due to the small size of the function and how trivial it may be.
inline does not always get embedded, there's a set of constraints that the function must be compliant with in order to be embedded, such as lacking loops and having a properly defined return.
macros instead are handled by the preprocessor, and they must always be static, which means that, unlike inline functions, you cannot access this-> within a macro unless it's already present within the context of the place where it's invoked at.
coal
in general, i avoid using macro functions as they increase the output size and don't provide the benefits of an inline function, which is just more convenient and safer to use.
Leovan
Whos know why on arch linux i can write g++ values like i want:
g++ -lSDL2 -lSDL2_images -lMyLib main.cpp
And on debian i need to put main.cpp first, then my shared lib and then sdl2?
g++ main.cpp -lMyLib -lSDL2 -lSDL2_images
Otherwise linker error: undefined reference
coal
coal
it's not about the distro, it's about why g++ acts differently on builds in different distros
coal
have you tried comparing versions?
coal