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
%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
'''''''
Yes of course
Then u don't need any trick
%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
- - 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
I've studied C just months back
Did you learn any other programming language?
'''''''
In the last year I've learnt basics of Python and C
Arta
I do not know why all over the internet Python is considered an angel and C ++ is a nightmare and a useless language. These words are funny, but on the other hand, they torment me
Nicely said Although I think that's because of the many Python libraries As well as the famous phrase "suitable for hacking" But I prefer this advantage of C++ to any other advantage: speed It's true,in C++ we often need to reinvent the wheel But I also like this
Strife
Nicely said Although I think that's because of the many Python libraries As well as the famous phrase "suitable for hacking" But I prefer this advantage of C++ to any other advantage: speed It's true,in C++ we often need to reinvent the wheel But I also like this
In my opinion, one of the main issues is the simplicity of the Python language. I know a lot of YouTubers who say that C ++ is not worth learning, C ++ is insanely hard. They talk about C ++ without any knowledge and encourage beginners to stay away from C ++
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
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.
Shrivatsa
Without code nobody can help.
Can i send a picture, I don't know how to wrap code and send??
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 ?
klimi
Hey guys i just wanted to know whether there is any pro coder in C ?
And what would you do with that information? (Little secret, yes there is)
Strife
Yes Maybe one of the reasons is the lack of jobs Although I do not know the situation in your country
The truth is that the web world and the C # language are popular in my country (although I'm not interested in the web world) But my goal in learning C ++ is to make games.
Arta
The truth is that the web world and the C # language are popular in my country (although I'm not interested in the web world) But my goal in learning C ++ is to make games.
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?🤔
Anonymous
How I can remember how to programming if I do not program for a while.
Anonymous
I got busy with university
Leovan
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
One of the possible problems is you try to print uninitialized variable. For example: int x; std::cout << x; // in x stored garbage from previous programs which used this memory cell (random value)
klimi
cmd like DOS
oh you mean cli? okay c:
Arta
oh you mean cli? okay c:
😂😂 sorry,yeh,cli
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]); }
No Name
doesn't scanf take whole line as an input?
This will read subsequent characters until a whitespace is found (whitespace characters are considered to be blank, newline and tab)
coal
unless it has a string-like format code, in that case it must take whitespace in account
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?
Abhishek
For what
i was using float main() for calling my main function but my ide showed warning
Pavel
i was using float main() for calling my main function but my ide showed warning
You should not call main manually, it's a special function from which the execution starts. And the return value is used as error code for the OS (that's why it's int)
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
Pavel
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 }
Yes, you can do that, you can also make a function overload that calls the function with three arguments passing the default value to the third one. Both have pros and cons
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
coal
i was using float main() for calling my main function but my ide showed warning
main() is already called by libc, you dont need to call it manually
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.
Pavel
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.
Macros work before C/C++ compiler is even involved, they don't check a lot of things that related to the language and can break logic of your program. imagine you have a macro function like #define SQR(x) (x)*(x) Then you can call it like this int i = SQR(++a); or int i = SQR(heavyFunctionCall()); (hope you see how it goes wrong) inline is working on the language level so it is much safer and in most cases more readable and easy to work with. However inline doesn't guarantee that the function will be inlined (either it can be not possible in some cases, or compiler will decide that inlining of this function will not improve the performance). There are compiler-specific ways to force-inline functions if you really want to ensure it will be inlined
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
it's not about the distro, it's about why g++ acts differently on builds in different distros
coal
have you tried comparing versions?
Leovan
strange because that'd only work if the implementation is different
I found answer on stackoverflow about g++ order of values are important, but on my arch its not necessary, idk why