int main(){
int i = 0;
while(i < 2){
char str[10];
printf("%p\n", str); //outputs same address both the times
i++;
}
i = 0;
while(i<2){
char *str;
str = (char*)malloc(10*sizeof(char));
printf("%p\n", str); //outputs two different addresses
i++;
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,为什么在循环中声明相同的字符数组给出相同的地址,尽管变量被声明两次不同的时间.所以根据我的理解,它应该为它分配新的内存.但它每次都返回相同的地址.
在动态分配内存的第二个中,它返回两个不同的地址,这是可以理解的,因为malloc每次都会为我找到新的连续内存块.
但为什么它在第一种情况下打印相同的地址?
我有以下代码:
在我的html中
<h1 id="heading">My Site</h1>
Run Code Online (Sandbox Code Playgroud)
在我的CSS中
#heading{
font-size: 16px;
color: #333333;
}
Run Code Online (Sandbox Code Playgroud)
当我在控制台时
document.getElementById("heading").style.fontSize
Run Code Online (Sandbox Code Playgroud)
它给:””
但当我这样做时
$("#heading").css("fontSize")
Run Code Online (Sandbox Code Playgroud)
它给出:16px
即使我打印整个样式对象,vanilla javascript 显示所有空白值,但 jquery 显示正确的结果。
两者为何有差异?
var a = function b() {
};
console.log(typeof b); //gives undefined
console.log(typeof a); //gives function
Run Code Online (Sandbox Code Playgroud)
为什么两个输出的差异?
我理解函数表达式和函数语句之间的区别,但不能理解上面的输出.
据我所知,javascript var a
指向分配给命名函数b的内存.在这种情况下typeof b
也应该返回,function
但它返回undefined
有什么解释吗?