<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.ta.in.th/index.php?action=history&amp;feed=atom&amp;title=Typedef_vs</id>
	<title>Typedef vs - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.ta.in.th/index.php?action=history&amp;feed=atom&amp;title=Typedef_vs"/>
	<link rel="alternate" type="text/html" href="https://wiki.ta.in.th/index.php?title=Typedef_vs&amp;action=history"/>
	<updated>2026-05-02T18:15:00Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0-alpha</generator>
	<entry>
		<id>https://wiki.ta.in.th/index.php?title=Typedef_vs&amp;diff=107&amp;oldid=prev</id>
		<title>Tata: Created page with &quot;ในการกำหนดชื่อชนิดตัวแปรใหม่ของเราเองขึ้นมา ในการเลือกใช้ระ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.ta.in.th/index.php?title=Typedef_vs&amp;diff=107&amp;oldid=prev"/>
		<updated>2019-03-07T17:19:04Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;ในการกำหนดชื่อชนิดตัวแปรใหม่ของเราเองขึ้นมา ในการเลือกใช้ระ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;ในการกำหนดชื่อชนิดตัวแปรใหม่ของเราเองขึ้นมา&lt;br /&gt;
ในการเลือกใช้ระหว่าง '''typedef''' กับ '''#define''' '''''ต่างกันยังไง'''''&lt;br /&gt;
&lt;br /&gt;
1.) '''วิธีการประกาศ'''&lt;br /&gt;
 #define MY_TYPE int&lt;br /&gt;
 typedef int My_Type;&lt;br /&gt;
&lt;br /&gt;
2.) '''typedef''' obeys scoping rules just like variables, whereas '''define''' stays valid until the end of the file (or until a matching '''undef''').&amp;lt;br&amp;gt;&lt;br /&gt;
* '''typedef''' จะมีช่วง (scope) อยู่เหมือนประกาศตัวแปรเช่่น ถ้าประกาศนอก main() ก็จะเป็น global  ตัวแปร MY_TYPE ของเราก็จะมีผลทั้งโปรแกรม แต่ถ้าประกาศใน {...} ก็จะมีผลใช้แค่ใน {...}&amp;lt;br&amp;gt;&lt;br /&gt;
* ส่วน '''define'''  จะมีผลตั้งแต่ตรงที่ '''#define''' ไว้  หรือจนกระทั่งจบ '''#undef''' &lt;br /&gt;
&lt;br /&gt;
3.) '''มีบางอย่างที่ typedef ทำได้  แต่ define ทำไม่ได้'''&lt;br /&gt;
 typedef int* int_p1;&lt;br /&gt;
 int_p1 a, b, c;  // a, b, and c are all int pointers.&lt;br /&gt;
 &lt;br /&gt;
 #define int_p2 int*&lt;br /&gt;
 int_p2 a, b, c;  // only the first is a pointer!&lt;br /&gt;
&lt;br /&gt;
และ&lt;br /&gt;
&lt;br /&gt;
 typedef int a10[10];&lt;br /&gt;
 a10 a, b, c; // create three 10-int arrays&lt;br /&gt;
&lt;br /&gt;
และ&lt;br /&gt;
&lt;br /&gt;
 typedef int (*func_p) (int);&lt;br /&gt;
 func_p fp // func_p is a pointer to a function that&lt;br /&gt;
           // takes an int and returns an int&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
อ้างอิง : http://stackoverflow.com/questions/1666353/is-typedef-and-define-the-same-in-c&lt;/div&gt;</summary>
		<author><name>Tata</name></author>
		
	</entry>
</feed>