#include <stdio.h>
int main(void)
{
/* /* Month */
printf("This month is May\n");
printf("This month is Jul\n"); */
/* Day of week */
printf("This day is Monday\n");
return 0;
}
#include <stdio.h>
int main(void)
{
#if 0
/* Month */
printf("This month is May\n");
printf("This month is Jul\n");
#endif
/* Day of week */
printf("This day is Monday\n");
return 0;
}
#include <stdio.h>
int main(void)
{
#if 0
/* Month */
printf(This month is May\n");
printf("This month is Jul\n");
#endif
/* Day of week */
printf("This day is Monday\n");
return 0;
}
Block comment ไม่ได้ปิดท้าย
#include <stdio.h>
int main(void)
{
#if 0
/* Month
printf("This month is May\n");
printf("This month is Jul\n");
#endif
/* Day of week */
printf("This day is Monday\n");
return 0;
}
อีกวิธีก็คือการใช้ Line comment ข้อเสียของวิธีนี้ก็คือ ต้องใช้ความสามารถของ IDE หรือ Text editor ช่วยในการ comment ในกรณีที่ code มีหลายๆบรรทัด ซึ่งส่วนใหญ่จะมีฟังชั่นเหล่านี้อยู่แล้ว
Line comment short cut ใน Sublime Text ก็คือ (Ctrl + /)
Line comment short cut ใน Notepad++ ก็คือ (Ctrl + k)
ตัวอย่าง Line comment
#include <stdio.h>
int main(void)
{
// /* Month*/
// printf("This month is May\n");
// printf("This month is Jul\n");
/* Day of week */
printf("This day is Monday\n");
return 0;
}
ดังนั้นหากจะต้องการที่จะเก็บ Code เก่าบางส่วนเอาไว้เพื่อเอาไว้อ้างอิง ก็ขอแนะนำให้ใช้ Line comment หรือหันมาใช้พวก Version control ดีกว่า
ขนาดของตัวแปรใน ภาษา C หรือ C++ นั้นจะขึ้นอยู่กับชนิดของ CPU และ Complier ซึ่งอาจจะเหมือนกันหรือต่างกันก็ได้ เรามาดูกันดีกว่าว่าแต่ละ CPU มีการกำหนดขนาดตัวแปรที่แตกต่างกันอย่างไร
จะเห็นได้ว่า แต่ละ CPU จะมีขนาดของตัวแปรที่กำหนดแตกต่างกันไป ดังนั้นการเขียนโปรแกรมในภาษา C หรือ C++ แล้วนำเอาไปใช้งานในแต่ละ CPU จึงต้องระมัดระวัง เนื่องจากขนาดของตัวแปรที่แตกต่างกันอาจจะทำให้โปรแกรมของเราทำงานได้ไม่ถูกต้องก็ได้
#include <stdio.h> /* For command line input and output */
#include <float.h> /* For limits on floating-point types */
int main(void)
{
printf("min float is %.6e\n", FLT_MIN);
printf("max float is %.6e\n", FLT_MAX);
printf("float provide %u decimal digits precision.\n\n", FLT_DIG);
printf("min double is %.15e\n",DBL_MIN);
printf("max double is %.15e\n", DBL_MAX);
printf("double provide %u decimal digits precision.\n\n", DBL_DIG);
printf("min long double is %.18Le\n", LDBL_MIN);
printf("max long double is %.18Le\n", LDBL_MAX);
printf("long double provide %u decimal digits precision.\n",LDBL_DIG);
return 0;
}