English 中文(简体)
C. 方案拟订语言、阵列、点
原标题:C programming language, array, pointer
int main()
{
    int j=97;
    char arr[4]="Abc";
    printf(arr,j);
    getch();
    return 0;
}

this code gives me a stack overflow error why? But if instead of printf(arr,j) we use printf(arr) then it prints Abc. please tell me how printf works , means 1st argument is const char* type so how arr is treated by compiler. sorry! above code is right it doesn t give any error,I write this by mistake. but below code give stack overflow error.

#include <stdio.h>
int main()
    {
       int i, a[i];
       getch();
       return 0;
    }

since variable i take any garbage value so that will be the size of the array so why this code give this error when i use DEV C++ and if I use TURBO C++ 3.0 then error:constant expression required displayed. if size of array can t be variable then when we take size of array through user input.no error is displayed. but why in this case.

问题回答

请告诉我,印刷作品是如何做的。

首先,只向(<>!>第1条论点提供或验证的外用户提供或证明。

printf() accepts a variable number of arguments after the required const char* argument (because printf() is what s called a variadic function). The first const char* argument is where you pass a format string so that printf() knows how to display the rest of your arguments.

如果<代码>ar 特征阵列含有用户表示的数值,则如果该示意图含有这些格式持有人,则该代码可能会造成一种过失,因此,该格式示意图应始终是硬编码不变的(或经验证)。 你的代码样本非常简单,足以证明它确实是固定的,但是,它仍是一种良好做法,用于<条码>(>%s”,rr)显示体状,而不是将其直接传递给第一种论点(除非你当然绝对必须这样做)。

尽管如此,你使用格式持有人(从<代码>%开始)来编排产出。 如果想显示:

页: 1

然后请<代码>印本(:

printf("%s %d", arr, j);

<%s notess:第二论点应被解释为无效的扼杀的点。 www.un.org/Depts/DGACM/index_french.htm 第三个论点应被解释为已签署的原则。

这部法典给我留下了flow的超支原因?

See See See AndreyT 回答。

www.un.org/Depts/DGACM/index_spanish.htm 我认为,现在,《任择议定书》将行为描述改为完全不同的,因此我的解释不再适用于他的法典。 然而,我就variadic的职能提出的要点仍然不变。

该守则导致打字无效(或类似),因为你没有宣布职能<条码>。 http://www.un.org/Depts/DGACM/index_french.htm 用C语说,在打电话之前,它始终必须履行clare<>m> variadic的职能。 这一要求的实际原因是,假肢功能(而且往往)可能需要采取一些特殊的做法来论证。 通常称为a打公约>。 如果你忘记在发出警告之前宣布一项行动,那么99年前的汇编者将假定它是一种普通的非宗教职能,并把它称为普通职能。 I.e. 它将使用错误的电话公约,而这反过来又会导致阻断无效。 所有这一切都取决于执行:有些人甚至似乎被“工作”罚款,有些人将坠毁。 但无论如何,你在打电话之前必须宣布行使职权。

在这种情况下,请列入<代码><stdio.h>。 http://www.ohchr.org。 Header file <stdio.h> is a standard Header which contained the declaration of f。 你们愿意这样做;因此,错误(很可能)。 不能保证100%,因为它取决于执行。

否则,你的法典是有效的。 守则是多余的,因为你通过<编码>jf,而没有为之提供格式细节,但这不是一个错误——f。 只是忽视了外语。 无论如何,你的代码应为<代码>Abc。 添加<条码>#include <stdio.h>,在你的代码一开始,它就应当做一些工作,假定你想要做些什么。

这部法典

#include <stdio.h>

int main()
{
    int j=97;
    char arr[4]="Abc";
    printf(arr,j);
    return 0;
}

is a strange, but perfectly valid C program with a perfectly defined output (adding at the end of the output would be a good idea though).

在您的行文中,int i, a [i]; in the amendedcode, a is a changing-length range of i elements, but i is un initialized. 因此,贵方案没有界定行为。

参看C种语文的体格,作为<代码>char*处理,f功能可直接打印。 在使用这一功能印刷体时,应当使用这种代码:

printf("%s", arr);

百分比表示第一个变量为char*

如果你想要印刷双rr,你应首先确定格式:

printf("%s%d", arr, j);

%d 说明第二个变量为int的功能

我怀疑<>印本()问题是一个红 her,因为如果一个无名的,将无视其他论点。

Have you debugged your program? If not can you be sure the fault isn t in getch()?
I cannot duplicate your issue but then I commented out the getch() for simplicity.

BTW,为什么你没有使用fgetc(getchar()? 你们是否打算使用,在较大的方案中使用<>>?

<>============================================================================================================================================================================================================================================================== 在你的编辑===之后添加

Okay, 而不是红 her, 只是被占领土的错误。

C++确实允许分配一个大小不一的阵列;正如你所推断的那样,你基本上以随机(垃圾)大小和溢出的 st。 当你与C++共同汇编时,通常不再编纂C和规则改动(视特定汇编者而定)。

尽管如此,我不理解你的问题——当我们通过用户投入计算阵列面积时,你需要用“更清楚。 ......





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...