$a = 1;
$b = $a + $a + $a++;
echo $b; //输出3
echo "
";
$d = 1;
$c = $d + $d++;
echo $c; //输出3
?>
大部分人答案:
$b=5; //错的
$c=3;
这里有人知道为什么两个结果是一样的嘛
回复讨论(解决方案)
其实没有为什么,C 就是这样的
#include "stdio.h"#include "conio.h"main(){ int a=1,b=1; printf("%d %d\n", a+a++, b+b+b++); getch();}3 3
按语法说明
$b = $a + $a + $a++;
得到 3 是符合规则的
而 $c = $d + $d++; 得到 3 是不符合规则的
因此,将 ++ 和 + 混合使用,并不能一定得到预期的结果
楼主这个是PHP哦 非C哦
结果确实是两个3哦
和php版本有关。
php4得出的是3
2
Interactive mode enabled
$a = 1;
$b = $a + $a + $a++;
echo $b; //输出3
echo "
";
$d = 1;
$c = $d + $d++;
echo $c; //输出3
?>
^Z
Content-type: text/html
X-Powered-By: PHP/4.3.2
3
2
又见坑爹无意义面试题
呵呵 面试总是很坑 戳戳锐气
第一个,计算的顺序是($a+$a)+$a++,先计算($a+$a)=2,在得到$a++的执行结果1,此时$a的值变为2,但是($a+$a)=2的结果已经存入内存,因此$a为2不影响前面的计算结果,得到(1+1)+1=3
第二个,则是先得到$d++的执行结果1,此时$d的值变为2,所以结果时2+1=3
面试的不着调,他应该考一些项目东西
第一个,计算的顺序是($a+$a)+$a++,先计算($a+$a)=2,在得到$a++的执行结果1,此时$a的值变为2,但是($a+$a)=2的结果已经存入内存,因此$a为2不影响前面的计算结果,得到(1+1)+1=3
第二个,则是先得到$d++的执行结果1,此时$d的值变为2,所以结果时2+1=3
按优先级应该是先执行++ 再执行+运算符把
你这个是先执行+然后再执行++?
第一个,计算的顺序是($a+$a)+$a++,先计算($a+$a)=2,在得到$a++的执行结果1,此时$a的值变为2,但是($a+$a)=2的结果已经存入内存,因此$a为2不影响前面的计算结果,得到(1+1)+1=3
第二个,则是先得到$d++的执行结果1,此时$d的值变为2,所以结果时2+1=3
按优先级应该是先执行++ 再执行+运算符把
你这个是先执行+然后再执行++?
第一个是非结合。此时++递增的优先级高,因此先计算$a++;
第二个是左结合,计算方向从左到右,先计算$a+$a,再计算$a++
第一个,计算的顺序是($a+$a)+$a++,先计算($a+$a)=2,在得到$a++的执行结果1,此时$a的值变为2,但是($a+$a)=2的结果已经存入内存,因此$a为2不影响前面的计算结果,得到(1+1)+1=3
第二个,则是先得到$d++的执行结果1,此时$d的值变为2,所以结果时2+1=3
按优先级应该是先执行++ 再执行+运算符把
你这个是先执行+然后再执行++?
第一个是非结合。此时++递增的优先级高,因此先计算$a++;
第二个是左结合,计算方向从左到右,先计算$a+$a,再计算$a++
既然$a++优先级高,那$a++ 以后 再计算$a+$a的时候 $a应该是2啊 怎么$a还会是1啊
感觉像大学里的无聊考试题,谁tm的在项目里这么写谁就是跟leader过不去!
------------------------------------------------------AutoCSDN签名档------------------------------------------------------
码农场??码农播种代码、放牧思想的农场!冰糖网
感觉像大学里的无聊考试题,谁tm的在项目里这么写谁就是跟leader过不去!
------------------------------------------------------AutoCSDN签名档------------------------------------------------------
码农场??码农播种代码、放牧思想的农场!冰糖网
兄弟没办法啊,谁都不想搞啊,项目中几乎不用
不过越大公司越考这些啊 唉 这家是迅雷的哦
第一个,计算的顺序是($a+$a)+$a++,先计算($a+$a)=2,在得到$a++的执行结果1,此时$a的值变为2,但是($a+$a)=2的结果已经存入内存,因此$a为2不影响前面的计算结果,得到(1+1)+1=3
第二个,则是先得到$d++的执行结果1,此时$d的值变为2,所以结果时2+1=3
按优先级应该是先执行++ 再执行+运算符把
你这个是先执行+然后再执行++?
第一个是非结合。此时++递增的优先级高,因此先计算$a++;
第二个是左结合,计算方向从左到右,先计算$a+$a,再计算$a++
既然$a++优先级高,那$a++ 以后 再计算$a+$a的时候 $a应该是2啊 怎么$a还会是1啊
说了第二个是连续加法,结合方向是从左至右,是先算($a+$a)=2的,之后再去计算$a++时,$a变为2,但是($a+$a)的计算结果已经进入内存,不再受$a值得影响。仔细去看看手册关于优先级这部分的说明吧。注意下各种运算符的结合方向
曾经出现过这样的帖子,当时我也有点纠结。在官方手册中,出现的“运算符的结合方向”是如何考虑的。
我不太了解C的运算方式。自己的解释是:
$a = 1;
$b = $a + $a + $a++;//PHP先计算了$a + $a(尽管$a++的优先级高),最后得到3
$d = 1;
$c = $d + $d++ //PHP先计算了$d++,在计算$d +
不知道这样理解对不对。
我不太了解C的运算方式。自己的解释是:
$a = 1;
$b = $a + $a + $a++;//PHP先计算了$a + $a(尽管$a++的优先级高),最后得到3
$d = 1;
$c = $d + $d++ //PHP先计算了$d++,在计算$d +
不知道这样理解对不对。
我觉得对的,其实加上括号就可以更明显的看出来优先级了。
($a + $a++);//由执行顺序//1、$a++//2、$a//再由$a = 1;$b = $a++;echo($a.'-'.$b);//结果$a为2, $b为1 即($a++)结果为1;//所以$a + $a++ = 2+1 为3//式1$b = $a + ($a + ($a + ($a + $a++)));//执行顺序//1、($a + $a++) //2、($a + ($a + $a++))//...括号优先//因为1先被执行,所以$a变量值被改变了,后面的顺序执行都会按改变的值计算//结果:$b = 2 + (2 + (2 + (2 + 1)));//式2$b = $a + $a + $a + ($a + $a++);//等同于$b = (($a + $a) + $a) + ($a + $a++);//执行顺序//1、($a + $a)//2、($a + $a) + $a)//......括号优先,相同符号 不加括号顺序执行//执行结果为$b = 1+1+1+($a + $a++) 即$b=3+(2+1)//最后$b = $a+$a++;//等同 式1$b = $a+$a+$a++;//等同 式2
就算知道茴香豆的回有好几种写法那又怎样,会一种就行了。其他的你一辈子都用不到
C那边叫Undefined behaviour(未定义行为),标准里面没规定,如何实现是编译器的事情,不同的编译器得到不同结果是正常的,或者有的根本编译不了。
研究这些东西做甚。

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
