简体   繁体   English

Xcode 5中的简单方法调用和传递的值不会改变

[英]Simple method call in Xcode 5 and passed value won't change

I'm a noob to Xcode and am reading the Big Nerd Ranch book and its asking me to do example programs in simple C to get me familiar with the language, however its asked me to create a program that calls a method from main and passes an int and does a square calculation and the printf to defog screen. 我是Xcode的新手,正在阅读Big Nerd Ranch一书,它要求我使用简单的C语言编写示例程序以使我熟悉该语言,但是它要求我创建一个从main和pass调用方法的程序一个int并进行平方计算,然后将printf设置为除雾屏幕。 Here is the program:- 这是程序:

#include <stdio.h>

void doTheMath(int numberToSquare)
{
    int numberSquared = numberToSquare * numberToSquare;
    printf("%d squared is %d\n",numberToSquare,numberSquared);

}

int main(int argc, const char * argv[])
{

    doTheMath(5);
    return 0;

}

As you can see I am passing the value 5 to the method and it prints 25 on screen when i run the code. 如您所见,我将值5传递给该方法,当我运行代码时,它在屏幕上显示25。 IF I then change 5 to 15 to get it to write out a different value, it doesn't. 如果然后我将5更改为15,让它写出一个不同的值,那不是。 It still writes out 5 squared, not 25 squared. 它仍然写出5平方,而不是25平方。

In debug and step through the value is wrong and isn't changed. 在调试和逐步调试中,该值是错误的,并且不会更改。

I've closed the project and Xcode and still it doesn't work all of the time and then sometimes it does reflect the changed value. 我已经关闭了项目和Xcode,但仍然不能始终使用它,有时它确实反映了更改后的值。

The project Type is an OSX application / command-line tool. 项目类型是OSX应用程序/命令行工具。 The project is stored on my NAS. 该项目存储在我的NAS中。

Your code is correct and when I test it in Xcode and change the 5 to 15 and run it, I get the correct answer returned. 您的代码正确,当我在Xcode中对其进行测试并将5更改为15并运行它时,我得到了正确的答案。 Make sure you save your file after you make the change, and you could also try to clean your project (Product > Clean). 进行更改后,请确保保存文件,还可以尝试清理项目(产品>清理)。

Sometimes Xcode just does strange things . 有时Xcode会做一些奇怪的事情。 . .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM