小编ElR*_*ito的帖子

这段代码如何跳转到最后一个字符串并反转堆栈?

我正在学习C,这是一个自学成才的事情.这很好,但是当我有问题时会变得毛茸茸,所以我希望得到一些帮助!

我有一些代码,我被指示写,我理解代码,我理解堆栈如何工作(取一个,进入另一堆等),main()并将始终先运行.

但我不明白为什么,在numberOfBottles达到0之后,它不会继续循环.为什么它首先反转堆栈,它是如何跳转到最后一个字符串的呢?

#include <stdio.h>

void singSongFor(int numberOfBottles)
{
    if (numberOfBottles == 0)
    {
      printf("there are simply no more bottles of beer on the wall. \n\n");
    } 
    else 
    {
        printf("%d bottles of beer on the wall. %d bottles of beer. \n", numberOfBottles, numberOfBottles);
        int oneFewer = numberOfBottles - 1;
        printf("Take one down, pass it around %d bottles of beer on the wall. \n\n", oneFewer);

        singSongFor(oneFewer);
        printf("Put a bottle in the recycling, %d empty bottles …
Run Code Online (Sandbox Code Playgroud)

c stack

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

标签 统计

c ×1

stack ×1