Can prefix and post be used simultaneously with variable in c

#include <stdio.h> 

int main()
{
    char *q;
    char *p = "sweta";
    q = ++p++;
    printf("%s", q);
}

What is the result, this program is valid because it gives an error l of the required value.

+3
source share
4 answers

q = ++p++; it won't even compile in C or in C ++

The post increment statement has a higher precedence than the pre increment statement

So, q= ++p++interpreted as q = ++(p++). Now the post increment statement returns an expression rvalue, while the preincrement statement requires its operand to be lvalue.

ISO C99 (Section 6.5.3.1/1)

Constraints

lvalue.

+6

, .

+3

/ . , , . C/++ .

q, q=(p+=2); q=++p++;

+1

, . - . , .

:

#include <stdio.h> 

int main()
{
    char* q;
    char* p = "sweta";
    q = p++;
    q = ++p;
    printf("%s\n", q);
}

:

eta
+1

Source: https://habr.com/ru/post/1759251/


All Articles