小编Aas*_*ahi的帖子

变量如何在同一时间点有两个不同的地址?

我尝试使用指针来玩一些指定值'i'和我发现的内容,因为有两个不同的地址分配给声明%u和%lu,%llu.变量如何可能在同一个执行实例中具有两个不同的地址 -

#include <stdio.h>
int main(void)
{
  int i;
  float f;
 printf("\nEnter an integer:\t");
 scanf("%d",&i);

  printf("\nValue of address of i=%u",&i);
  printf("\nvalue of address of i=%d",&i);
  printf("\nValue of address of i=%lu",&i);
  printf("\nValue of address of i=%llu",&i);

  printf("\nvalue of i=%d",i);
  printf("\nvalue of i=%u",i);
  printf("\nvalue of i=%lu",i);
  printf("\nvalue of i=%llu\n",i);

}
Run Code Online (Sandbox Code Playgroud)

这是输出 -

aalpanigrahi@aalpanigrahi-HP-Pavilion-g4-Notebook-PC:~/Desktop/Daily programs/pointers$ ./pointer001

    Enter an integer:   12

    Value of address of i=1193639268
    value of address of i=1193639268
    Value of address of i=140725797092708
    Value of address of i=140725797092708
    value of i=12 …
Run Code Online (Sandbox Code Playgroud)

c pointers memory-address

1
推荐指数
1
解决办法
135
查看次数

为什么这个生成垃圾的价值不像其他程序?

我试图对阵列初始化进行一些实验.在下面提到的程序中,我初始化了一个数组,同时提到了它的维度,同时,我提到了数组的值,但是我在初始化过程中提到的数组的总数值小于数组的维数.数组,因此我期待某种形式的大垃圾值(如第二个程序所示,这基本上是为了表明,除非为数组的元素赋值将基本上生成垃圾值),但这个数组最后一个值是仅产生0作为输出.为什么这样 ??

程序1 -
(而不是数组最后一个元素的大垃圾值,而是生成的输出为0.)

#include <stdio.h>
int main(void)
{
    int array[5]={1,2,3,4};
    printf("\nValues of array are :");
    for (int i = 0; i < 5; ++i)
    {
        printf("\t%d",array[i]);
    }
    printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

程序2-
(这主要是为了表明值被分配给一个数组,它只是生成一些大的垃圾值)

#include <stdio.h>
int main(void)
{
    //For accepting the size of an array
    int num;
    printf("\nEnter the size of an array:\t");
    scanf("%d",&num);
            //Declaration of an array
    int array[num];
    //Printing output of an array
    for (int i = 0; i < num; ++i)
    {
        printf("\nValue …
Run Code Online (Sandbox Code Playgroud)

c arrays initialization

0
推荐指数
1
解决办法
59
查看次数

标签 统计

c ×2

arrays ×1

initialization ×1

memory-address ×1

pointers ×1