FAQ Database Discussion Community


i % 2 == 0 ? arr[i] = 0 : arr[i] = 1; Ternary operator error

c,arrays,ternary-operator,lvalue
About ternary operator. I was rewriting an if-else statement in C, using the more clean ternary operator. Here´s the code: #include <stdio.h> #include <stdlib.h> int main() { int arr[10]; int i; // for ( i = 0; i < 10; i++ ) // { // if ( i % 2...

Is there exception to rule that if address can be find out using & it's lvalue?

c++,c++11,memory-address,lvalue,rvalue
Is there any exception to rule that if I can find address using & it's l-value otherwise r-value? For example, int i; &i will give address of i, but I cannot take address of (i + 5), unless I is pointer or array. Regards ...

Lvalue reference initialization from brace-enclosed initializer list fails to compile

c++,reference,lvalue
I have very simple program: #include <iostream> using namespace std; int main() { string var {"test"}; string &lr {var}; cout << var << "\n"; cout << lr << "\n"; } Compile it as follows: g++ ./test.cpp -g3 -std=c++0x ./test.cpp: In function ‘int main()’: ./test.cpp:9:19: error: invalid initialization of non-const reference...

Bind temporary rvalue to reference lvalue in std::vector constructors

c++,vector,pass-by-reference,lvalue,rvalue
Until now, I thought that we cannot pass a temporary rvalue to a lvalue reference. But just recently, I took a closer look on the fill constructor of std::vector: explicit vector (size_type n, const value_type& val = value_type(), const allocator_type& alloc = allocator_type()); const value_type& val is a reference lvalue...

Overload resolution with rvalue reference to const char *

c++,c++11,lvalue,rvalue
#include <iostream> using namespace std; void f(const char * const &s) { cout << "lvalue" << endl; } void f(const char * const &&s) { cout << "rvalue" << endl; } int main() { char s[] = "abc"; f("abc"); f(s); } Output: rvalue rvalue Why isn't the output "rvalue lvalue"?...

why c++ rvalue is not immutable

c++,lvalue,rvalue
Code: void test(int&& a) { a++; std::cout << a << std::endl; } and execute: test(0); why output 1? Cause I think 0 is rvalue, it could not be changed....

C++ Expression must be a modifiable lvalue

c++,expression,lvalue
writing this program for my c++ class and im running into an issue. My program reads the inputtted name and stores it into name it then wants to check for correct parameters under _name.. here are my class and its header file. My error is specifically under ::setName where i...

C++ Error: lvalue required as unary '&' operand

c++,class,lvalue
I have created a class named node. It is defined as follows: class node { private: int key; node * next; public: void setkey(int key); void setnext(node * next); int getkey(); node * getnext(); }; These functions are basic getter and setter functions. Now, if I try to do this:...