Author Topic: return 0; กับ return(0); ต่างกันยังไง  (Read 5475 times)  Share 

0 Members and 2 Guests are viewing this topic.

Offline thanachit

  • นักศึกษาปริญญาตรี
  • เทพไอที
  • *
  • Posts: 877
  • Karma: +0/-0
  • Gender: Male
  • somebody out there
#include<stdio.h>
int main()
{
    printf("test");
    return 0;
}

หุหุ แล้วมันใช้ return(0);
ได้ด้วย
อยากรู้ว่ามันต่างกันยังไงอ่ะครับ
I wanna be there when you're in need.

Offline WingGundamZeroCustom.co.th

  • นักศึกษาปริญญาตรี รุ่นที่ 2
  • พระเจ้าจอร์ช มันขุดได้ยอดมากเลย
  • *
  • Posts: 2,726
  • Karma: +1/-0
  • Gender: Male
  • My name is Rx-93 ν Gundam
    • Blog@WingInfotech.net
Re: return 0; กับ return(0); ต่างกันยังไง
« Reply #1 on: December 13, 2007, 06:34:39 PM »
ตอบตามความรู้ที่มีอยู่นะครับ

return 0 กับ return(0) เหมือนกันครับ ไม่ได้แตกต่างอะไรกันเลย มันเป็นเพียงแค่ syntax ของมันเท่านั้น ที่จะสามารถเขียนได้หลายแบบ แต่ให้ผลเหมือนกันครับ
I will change the world, to the better day.

My blog, My world: http://blog.winginfotech.net




Offline YiM

  • นักศึกษาปริญญาตรี
  • ไอทีมือเก๋า
  • *
  • Posts: 265
  • Karma: +0/-0
Re: return 0; กับ return(0); ต่างกันยังไง
« Reply #2 on: December 13, 2007, 07:52:46 PM »
int x = 5 + 2;
กับ
int x = (5 + 2);

ต่างกันมั้ย?

วงเล็บในภาษาซีใช้ได้สองอย่าง
อย่างแรกคือทำการแบ่งลำดับการคำนวน เช่น 6 + (5 / 2)  คือให้ทำ 5 / 2 ก่อน แล้วค่อยบวกกะ 6
อย่างที่สอง คือเอาไว้กั้นเขตแดนของ parameter ใน function

แต่ return ไม่ใช่ฟังก์ชั่น ดังนั้นหน้าที่ของวงเล็บจึงเป็นหน้าที่แรก ซึ่ง compiler จะ compile ในวงเล็บก่อน ... มันก็เป็นเช่นนั้นแล

Offline WingGundamZeroCustom.co.th

  • นักศึกษาปริญญาตรี รุ่นที่ 2
  • พระเจ้าจอร์ช มันขุดได้ยอดมากเลย
  • *
  • Posts: 2,726
  • Karma: +1/-0
  • Gender: Male
  • My name is Rx-93 ν Gundam
    • Blog@WingInfotech.net
Re: return 0; กับ return(0); ต่างกันยังไง
« Reply #3 on: December 13, 2007, 11:00:21 PM »
นั่นสิเนาะ ก็ไม่เคยเห็นใครเขียน

return (x + 2) * 4;

เหมือนกันเนาะ
I will change the world, to the better day.

My blog, My world: http://blog.winginfotech.net




Offline thanachit

  • นักศึกษาปริญญาตรี
  • เทพไอที
  • *
  • Posts: 877
  • Karma: +0/-0
  • Gender: Male
  • somebody out there
Re: return 0; กับ return(0); ต่างกันยังไง
« Reply #4 on: December 14, 2007, 02:45:58 PM »
นั่นสิเนาะ ก็ไม่เคยเห็นใครเขียน

return (x + 2) * 4;

เหมือนกันเนาะ

ลองสิ
I wanna be there when you're in need.

Offline thanachit

  • นักศึกษาปริญญาตรี
  • เทพไอที
  • *
  • Posts: 877
  • Karma: +0/-0
  • Gender: Male
  • somebody out there
Re: return 0; กับ return(0); ต่างกันยังไง
« Reply #5 on: December 15, 2007, 06:54:01 AM »
มัน return กลับไปได้แหละ
I wanna be there when you're in need.