mito
mito
If you want to know what's actually happening regardless of any high level language, look at assembly code, it's a level higher than binary language.
mito
Yes, you can.
mito
You can use GNU debugger.
mito
Yes
M
#include<iostream>
using namespace std;
int fib(int x){
if(x<2){
return 1;
}
return fib(x-2)+fib(x-1);
}
int main(){
int a;
cout<<"enter the number for finding fib"<<endl; cin>>a; cout<<"the fact is "<<<fib(a)<<endl;
mito
https://godbolt.org/
Or use this website.
It's pretty handy.
M
#include<iostream> using namespace std;
int fib(int x) { if(x<2){
return 1;
}
}
return fib(x-2)+fib(x-1);
int main(){
int a;
cout<<"enter the number for finding fib"<<endl;
cin>>a;
cout<<"the fact is "<<fib(a)<<endl;
}
M
M
Now can I know what happens in return fib(x-2) + fib(x-1)
M
Actually I want to know how compiler is preserving value of variables
M
In each bit of command
²
mito
Actually I want to know how compiler is preserving value of variables
Compile that program, then download x64dbg and run it.
Open your Fibonacci executable and run it.
Attach the Fibonacci program process to x64dbg and set breakpoints at assembly code and observe the registers and program flow.
This is the easy way using GUI.
If you want command line, then use GNU debugger it is simple.
You first need to learn assembly and how data is stored in registers and all to know atleast how everything works at low level.
Chika
Is it possible to convert from a string datatype to an int datatype in c++?
mito
Hizmu(Vlad)
Hi guys. Tell me how best to do it.
My project consists of 3 libraries.
1. The library is built on mongoc that connects to mongodb
2. Log - built on spdlog
3. Account - which registers the user, authorization, and so on.
And I think how to do database logging. So far, I just have spdlog output. But how is it better to return an error from the library? With getError(), or create an ErrorHandler class, or let's say collection.find() should go as an error return value? If create an ErrorHandler then how to combine it with spdlog ? if getError() then what is it to return, a string or a struct?
Ster-Devs
Anonymous
Hi guys. Tell me how best to do it.
My project consists of 3 libraries.
1. The library is built on mongoc that connects to mongodb
2. Log - built on spdlog
3. Account - which registers the user, authorization, and so on.
And I think how to do database logging. So far, I just have spdlog output. But how is it better to return an error from the library? With getError(), or create an ErrorHandler class, or let's say collection.find() should go as an error return value? If create an ErrorHandler then how to combine it with spdlog ? if getError() then what is it to return, a string or a struct?
This depends on a lot of things. There is no one right answer. This depends on your code, your architecture and your Long Term Vision plans.
Basically you want a mechanism to do error handling from the Account library. How you do this depends on what clients of this library expect from the chosen error handling mechanism. Are you intending to create an alternative for clients to do if a call to your library fails? Or is the error that you return from your library just a FYI that you expect the client to log and not be able to do much after that.
If it is the former case, then designing an exception hierarchy would be a choice. If your organisation doesn't allow exceptions, then you can return a struct with as much information as possible to help the client recover or try alternatives.
If it is the latter case then you can return a error string encapsulated in a DBError struct (this allows you the possibility of extending this struct in future).
(Look at std::expected. This class is like EitherOr in Functional programming languages that aids with better error handling mechanisms. It is available only in C++23 but is easy to implement using C++14 itself. There are many implementations available).
The client can log the error string (if it is not a library itself) or pass it on to upstream clients (if it is another library) to inform about the error or even wrap it in an exception.
Again, like I said there is no one right answer and the choice depends on your needs and your future plans.
SR27
int main()
{
int p=5;
int &k=p;
k=2;
//printf("return value %d",f(p,p));
printf("\nafter work %d",p);
return 0;
}
SR27
it gives error
SR27
please help
Anonymous
post the error
SR27
main.c: In function ‘main’:
main.c:18:9: error: expected identifier or ‘(’ before ‘&’ token
18 | int &k= p;
| ^
main.c:19:6: error: ‘k’ undeclared (first use in this function)
19 | &k=3;
| ^
main.c:19:6: note: each undeclared identifier is reported only once for each function it appears in
Anonymous
i think what you want to do is
int* k = &p
Pavel
Anonymous
oh that’s right ahah i didn’t even realize it was c
SR27
#include<stdio.h>
#include<stdlib.h>
// using namespace std;
int f (int &x, int &c)
{
x=4;
c=5;
return x*c;
}
int main()
{
int p=5;
printf("return value %d",f(p,p));
return 0;
}
SR27
even this will not work in c ?
Dumb
SR27
just want o confirm
Dumb
you are using the addresses of parameters in f
Dumb
Dumb
so it could work differently
Pavel
SR27
SR27
means i can use & in c for only passing variable address , can't make reference variable.
Sajid
Hello guys,
Anyone works with multi agent conflict base search algorithm?
Hizmu(Vlad)
SR27
#include <stdio.h>
int f1() { printf ("Geeks"); return 1;}
int f2() { printf ("forGeeks"); return 1;}
int main()
{
int p = f1() + f2();
return 0;
}
SR27
When '+' Associativity is from left to right, why this program is ambiguous it should call f1 then f2.
Anonymous
Hussein
SR27
Hussein
c
what are you trying to do with & ?
Hussein
in c there is no ‘&’ in variable declaration
adnanhossainme
Pointer assign
SR27
i wanted to know that can i use & to make reference variable and can i do swap(a,b);//function call swap(int &a,int &b)//function defination
adnanhossainme
Just swap direct.
First store that value on another variable then change.
Hussein
Hussein
SR27
ok
SR27
adnanhossainme
    int me = 15;
    int *P = &me;
//pointer should be assign like this
adnanhossainme
Anonymous
Hi All, I have created a stack template class I have included the header file in main.cpp but it gives me error as undefined reference to every function I use from stack class. Please let me know what I am doing wrong here;
https://www.onlinegdb.com/ESs9QrysS
PS: if i include stack.cpp it works
Anonymous
SR27
Anonymous
Anonymous
Anonymous
guys what are smart pointers?
Anonymous
could you provide also an example?
/
Hi i need to know a thing
/
how can i make like a gui library without using opengl
/
for example using syscalls
/
to display things
/
and how does for exemple the bios of a computer display things when you enter the settings
/
i think it is made in c too
/
but i dont think there are syscalls or opengl