Talula
Ok so tell me what is the difference between thesetwo functions void fun(int* p); void fun(int* &p);
1. Pointer to P (Memory Location). 2. Pointer to the Address of P in memory location. But none are by value, they are both by reference to the memory location, now again you could be right about standards and what is written in books, but that is how computers work.
Pavel
Maybe... But passing information as a pointer is not by value but by reference to the location in memory which holds the value.
That is logical, but that's not what ..oh-my-gosh-how-to-type-this-nicknane.. is talking about. It's more about the standard's way of interpreting this behavior, which is not that straightforward logically but it makes clear sense from the language perspective.
𝐄𝐲𝐚𝐝
Helpful community. I must be here everyday!
Anonymous
1. Pointer to P (Memory Location). 2. Pointer to the Address of P in memory location. But none are by value, they are both by reference to the memory location, now again you could be right about standards and what is written in books, but that is how computers work.
Lol wrong. You don't understand references. That is the problem. You think everywhere there is an &, a pointer is being used. int* p is not a pointer to p but it is a pointer to an int. int* &p is not a pointer to the address of memory location of pointer to p, but it is a reference to a pointer and the name of the reference is p.
Pavel
What do you think is the meaning of "reference"?
I guess it's called lvalue reference, what I mean in this case
Pavel
May be wrong in these terms
𝐄𝐲𝐚𝐝
I think "2" Is just a value.
Sorry, just the address of p
Anonymous
I don't think you understand how computers work... I feel sorry for you.
Lol. You don't understand the syntax of the language and yet claim to know how it works. I have already said how references are implemented and yet you harp on the same thing again and again.
Pavel
What is lvalue in assembly?
It doesn't matter really in the context of this discussion. That's why I was saying from the beginning that the problem here is in terminology
Talula
Lol. You don't understand the syntax of the language and yet claim to know how it works. I have already said how references are implemented and yet you harp on the same thing again and again.
Terms but you said it is passing by value, it is not passing a variable by memory location means it is passed as a pointer in C, but "terms" for it could be different in C++, which a bookworm would know. But it is not passed by value...
Anonymous
It doesn't matter really in the context of this discussion. That's why I was saying from the beginning that the problem here is in terminology
Yes. Since the beginning am saying don't use "pass by reference" unless the parameter is a reference. The standard specifies what that is. So people can't just assign random meanings to it
Talula
c++ != asm
Then what is a reference if it is not a memory location?
Anonymous
Terms but you said it is passing by value, it is not passing a variable by memory location means it is passed as a pointer in C, but "terms" for it could be different in C++, which a bookworm would know. But it is not passed by value...
Not just me. The standard says so. People on Stackoverflow say so. And yet you seem to think you know more than all of us when you clearly can't comprehend basic code even
Anonymous
Then what is a reference if it is not a memory location?
In the C++ programming language, a reference is a simple reference datatype that is less powerful but safer than the pointer type inherited from C. The name C++ reference may cause confusion, as in computer science a reference is a general concept datatype, with pointers and C++ references being specific reference datatype implementations. The definition of a reference in C++ is such that it does not need to exist. It can be implemented as a new name for an existing object (similar to rename keyword in Ada).
Anonymous
Then what is a reference if it is not a memory location?
In computer science, a reference is a value that enables a program to indirectly access a particular data, such as a variable's value or a record, in the computer's memory or in some other storage device. The reference is said to refer to the datum, and accessing the datum is called dereferencing the reference. A reference is distinct from the datum itself. Typically, for references to data stored in memory on a given system, a reference is implemented as the physical address of where the data is stored in memory or in the storage device. For this reason, a reference is often erroneously confused with a pointer or address, and is said to "point to" the data. However, a reference may also be implemented in other ways, such as the offset (difference) between the datum's address and some fixed "base" address, as an index into an array, or more abstractly as a handle. More broadly, in networking, references may be network addresses, such as URLs. The concept of reference must not be confused with other values (keys or identifiers) that uniquely identify the data item, but give access to it only through a non-trivial lookup operation in some table data structure. References are widely used in programming, especially to efficiently pass large or mutable data as arguments to procedures, or to share such data among various uses. In particular, a reference may point to a variable or record that contains references to other data. This idea is the basis of indirect addressing and of many linked data structures, such as linked lists. References can cause significant complexity in a program, partially due to the possibility of dangling and wild references and partially because the topology of data with references is a directed graph, whose analysis can be quite complicated.
Talula
Precisely. It is an alias as far as the C++ standard is concerned
But again it is not passed by value... as I explain what is the meaning of passing by value.
Anonymous
But again it is not passed by value... as I explain what is the meaning of passing by value.
You don't explain what it means. The standard does. No one isgoing to build a compiler based on your assumptions.
Pavel
This really reminds me old good discussions about using word "method" in context of C++.
Talula
You don't explain what it means. The standard does. No one isgoing to build a compiler based on your assumptions.
It's not an assumption it is how computers work, there is nothing more than numbers pushed on stack and pop on function side... There is nothing else happening... but when you push a=10; It pushes 10 If it is a pointer It pushes the address.. If it is a reference it pushes an address...
Talula
so a pointer does not push what is inside the address?
No, pointer is the address for the variable, this address is pushed.
Anonymous
AHH ok thx
you should have understood by now anyway :)
𝐄𝐲𝐚𝐝
No, pointer is the address for the variable, this address is pushed.
Can we even push an address (I understand that puch = edit)
Kevin
you should have understood by now anyway :)
hahahaha im learning step by step no hurries
Kevin
Simone i will share my Code later
𝐄𝐲𝐚𝐝
😉
Kevin
So, what is pass by reference?
Kevin
JUST KIDDING
Kevin
Thanks for the explanations
𝐄𝐲𝐚𝐝
lol
Kevin
which code?
The one that i put at the very beggining
Anonymous
The one that i put at the very beggining
however in your program there is no reason to use references
Anonymous
Thanks❤️
A
Enter input numbers between 5.2 and 15.5 in a vector of 10 cells and display it
A
Someone can resolve this ?
Kevin
You have to try it
Kevin
the rules say it
artemetra 🇺🇦
hi guys, i come to c++ from a python background in python, you can set default parameters for functions or make them accept keyword arguments. afaik there's no way to do it in c++ so i have a question: i have a class with multiple attributes, how can i set specific values for them in the construction whilst not having to specify all of the arguments? (make them have default values)
artemetra 🇺🇦
OOH that's what they were called! i saw them multiple times in various tutorials but none mentioned the name of them, tysm!
Naman
Hey guys i don't know my my vsc is not working for c programming i need some geniune help whosoever can do that please dm me
Naman
Or can help me out here too
Naman
Vsc is visual studio code
Typing...
How can I make a object in class by the name of user input.
Hamster
Hey guys!
Hamster
I'm just beginning...should i go for Coding Ninjas? Basic to advance course for C nd C++ also data structure
Hamster
Anyone can suggest...
Shubh
Write a C program to take the values from user and evaluate the following expression: x = a + b % c / d % e * f – g;
Anonymous
Lol
Solution the question.
Anonymous
*solve
No. Don't solve it. Solution it, please.
Anonymous
OK
Thanks.
Puspam
Write a C program to take the values from user and evaluate the following expression: x = a + b % c / d % e * f – g;
int a,b,c,d,e,f,g; printf("Enter 7 numbers separated by space:\n"); scanf("%d %d %d %d %d %d %d", &a,&b,&c,&d,&e,&f,&g); int x=a + b % (int)((float)c / (float)d) % e * f - g; printf("%d", x);
TheBito
do you guys use 4coder for C or is there a better application?
Shubh
C++ by dr. Frank mitropolus .. How it is?
A
hello everyone, I would like to ask about a problem I got here. I appreciate a little clue also. Language : C++ So, I want to turn "AAAA" to "TTTT" and "TATT" to "ATAA". How to build a function to change that letters?
Talula
hello everyone, I would like to ask about a problem I got here. I appreciate a little clue also. Language : C++ So, I want to turn "AAAA" to "TTTT" and "TATT" to "ATAA". How to build a function to change that letters?
It could be a simple if statement... So let us say your string is a = "ATTA", check it using if (a[i]) where i is your variable in the for loop and if you see T, replace it with A and else replace it with T. replacing is simply saying a[i] = 'T' or whatever you want to replace it with.