Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++
C++
  1. Operators Precedence ใน C++

    ความหมาย Operator Precedence กำหนดการจัดกลุ่ม terms ในนิพจน์ Associativity กำหนดการจัดกลุ่ม operators precedence เท่ากัน โดยไม่มีวงเล็บ ตัวอย่าง x = 7 + 3 * 2; x = 13 (ไม่ใช่ 20) เพราะ * precedence สูงกว่า + ตาราง Precedence และ Associativity (สูง → ต่ำ) CategoryOperatorsAssociativity Postfix

  2. C++ Standard Library Header Files

    C++ Standard Library Header Files แบ่งตามหมวดหมู่ Utilities Library <cstdlib> - General utilities: program control, dynamic memory, random, sort, search <csignal> - Signal management (SIGINT, etc.) <csetjmp> - Save/jump execution context <cstdarg> - Variable argument lists

  3. C++ Standard Output Stream (cout)

    นิยาม std::cout เป็น object ของ class ostream แทน standard output stream narrow characters (char) Corresponds to C stdout คุณสมบัติ Default destination: console (shared กับ cerr/clog ได้) เขียนข้อมูล 2 แบบ: formatted (<<) และ unformatted (write) ประกาศใน <iostream> external linkage, s

  4. Operator ?-->? ใน C++ คืออะไร

    คำตอบสั้น ไม่มีออเปอเรเตอร์นี้ใน C++ เป็นการผสมผสานของหลายออเปอเรเตอร์ บริบท: Wrapper Types บางครั้งมี nested wrapper types (unique_ptr, shared_ptr, optional) ต้องเรียก .get() หลายครั้ง หรือ dereference หลายครั้ง length(); Long Arrow Operator C++98 introduce long arrow เพื่อลด .get() length(); /

  5. Standard Input Stream (cin) ใน C++

    นิยาม std::cin เป็น object ของ class istream แทน standard input stream narrow characters (char) Corresponds to C stdin คุณสมบัติ แหล่งข้อมูล: environment (keyboard, file) อ่านข้อมูล 2 แบบ: formatted (>>) และ unformatted (read) ประกาศใน <iostream> external linkage, static duration ตั

  6. C++ Standard Error Stream (cerr)

    นิยาม std::cerr เป็น object ของ class ostream แทน standard error stream สำหรับ narrow characters (char) Corresponds to C stderr คุณสมบัติ Destination: กำหนดโดย environment อาจ share กับ cout/clog เขียนข้อมูลได้ 2 แบบ: formatted (<<) และ unformatted (write) ประกาศใน <iostream> มี exter

  7. Basic Rules และ Idioms สำหรับ Operator Overloading ใน C++

    กฎพื้นฐาน 3 ข้อ 1. อย่า Overload ถ้าความหมายไม่ชัดเจน เมื่อความหมายของออเปอเรเตอร์ไม่ชัดเจนและ undisputed (ไม่ถูกยอมรับทั่วไป) ไม่ควร overload ควรสร้างฟังก์ชันที่มีชื่อชัดเจนแทน หัวใจของกฎนี้: อย่าทำมัน (Dont do it) มีเพียงไม่กี่กรณีที่เหมาะสม เพราะยากที่จะเข้าใจ semantics ของออเปอเรเตอร์ เว้นแต่ใ

  8. ความแตกต่างระหว่าง Dot (.) Operator และ Arrow (->) ใน C++

    บทนำ ) ใช้เข้าถึงสมาชิกของ class/struct/union (ของ class type) แต่ใช้ในสถานการณ์ต่างกัน กฎการใช้งาน a.b: ใช้เมื่อ b เป็นสมาชิกของ object (หรือ reference) a โดย a ต้องเป็น object จริง (หรือ reference) ของคลาส b: shorthand ของ (*a).b ใช้เมื่อ a เป็น pointer ไปยัง object เข้าถึงสมาชิก b ของ object ท

  9. cin, cout, cerr, clog Streams ใน C++

    ภาพรวม cin, cout, cerr, clog เป็น stream objects ใน <iostream> จัดการ standard input/output รายละเอียดแต่ละ Stream std::cin (Standard Input) Class istream, narrow characters (char) Corresponds to C stdin แหล่งข้อมูล: keyboard, file, environment ใช้ extraction operator >> หรือ member

  10. วิธี Initialize Memory ด้วย New Operator ใน C++

    ข้อจำกัดของ new Operator new ใน C++ จัดสรรหน่วยความจำเท่านั้น ไม่ initialize ค่า Default Initialization (ค่าเริ่มต้น) สำหรับ array of int ต้องการค่าเริ่มต้น 0 ใช้ syntax: new int[10](); ต้องใช้ empty parentheses () ไม่สามารถใช้ (0) หรือ expression อื่นได้ ใช้ได้เฉพาะ default initialization วิธีอื

  11. ความแตกต่างระหว่าง cerr และ clog streams ใน C++

    ความแตกต่างหลัก ทั้ง cerr และ clog เป็น object ของ stderr stream แต่ทำงานต่างกัน: 1. cerr - Un-buffered Standard Error Stream Instance ของ ostream class ใช้แสดง error message ทันที Un-buffered: ไม่มี buffer เก็บข้อความ ส่งออกทันที เหมาะสำหรับ critical errors ที่ต้องแสดงทันที 2. clog - Buffered

  12. เมื่อไหร่ควรใช้ 'friend' ใน C++

    Friend Function Friend function นิยามนอกคลาส แต่เข้าถึง private/protected members ได้ทั้งหมด Prototype อยู่ใน class definition แต่ ไม่ใช่ member function Friend สามารถเป็น Function / Function template Member function Class / Class template (ทั้งคลาสและสมาชิกทั้งหมดเป็น friend) การประกาศ class B

  13. ความแตกต่างระหว่าง cerr และ cout streams ใน C++

    ความแตกต่างพื้นฐาน cout: object ของ stdout stream (standard output) cerr: object ของ stderr stream (standard error) stdout และ stderr เป็น stream ต่างกัน แม้ทั้งคู่จะส่งไปยัง console โดยค่าเริ่มต้น การ redirect (piping) หนึ่งไม่ส่งผลต่ออีกอัน แนวทางปฏิบัติที่ดี (Best Practice) stdout (cout): ใ

  14. ความแตกต่างระหว่าง ++i และ i++ ใน C++

    ความแตกต่างหลัก Prefix (++i): เพิ่มค่า i แล้วคืนค่าใหม่ (increment แล้ว assign) Postfix (i++): คืนค่าเดิม แล้วค่อยเพิ่มค่า i (assign แล้ว increment) ตัวอย่าง #include <iostream> using namespace std; int main() { int x = 3, y, z; y = x++; // y = 3, x = 4 z = ++x; // x = 5, z

  15. Double Address Operator (&&) ใน C++

    นิยาม && เป็น reference operator ใหม่ในมาตรฐาน C++11 int&& a หมายถึง a เป็น r-value reference ใช้ประกาศพารามิเตอร์ฟังก์ชันเป็นหลัก รับเฉพาะ r-value expression เท่านั้น R-value vs L-value R-value: ค่าที่ไม่มี memory address เช่นตัวเลข 6, ตัวอักษร v, นิพจน์ (a+2) L-value: มี memory

  16. การเปรียบเทียบ endl และ \n ใน C++

    ความแตกต่างหลัก \n: พิมพ์ newline (platform-specific: Windows เป็น \r\n) ไม่ flush stream std::endl: พิมพ์ newline และ flush stream แนวทางการใช้งาน ปกติไม่ต้อง flush stream ทันที เพราะส่งผลต่อ performance ควรใช้ \n แทน ใช้ std::endl เมื่อต้องการ flush ด้วยตนเอง เช่น ต้องการให้ output แสดงให้ผู้ใ

  17. ความแตกต่างระหว่าง cin และ cout streams ใน C++

    ความแตกต่างหลัก cin: object ของ input stream ใช้รับ input จากไฟล์ console เป็นต้น cout: object ของ output stream ใช้แสดงผล output cin เป็น input statement, cout เป็น output statement ออเปอเรเตอร์ที่ใช้ cin ใช้ extraction operator >> cout ใช้ insertion operator << ตัวอย่าง: รับค่าแ

  18. Simple Arithmetic Operators Example Program ใน C++

    Arithmetic Operators พื้นฐาน 5 ตัว Addition (+) Subtraction (-) Division (/) Multiplication (*) Modulo (%) ใช้ได้กับ arithmetic operations ทั้งหมดใน C++ ตัวอย่างโปรแกรมครบ #include <iostream> using namespace std; int main() { int a = 21; int b = 10; int c; c = a + b;

  19. Compound Assignment Operators ใน C++

    รูปแบบ Compound assignment operators มีรูปแบบ e1 op= e2 โดย: e1 ต้องเป็น modifiable l-value ไม่ใช่ const e2 ต้องเป็น arithmetic type หรือ pointer (ถ้า op เป็น + หรือ -) พฤติกรรมเทียบเท่า e1 = e1 op e2 แต่ e1 ถูกประเมินเพียงครั้งเดียว รายการ Compound Assignment Operators Operatorคำอธิบาย *=คู

  20. Increment (++) และ Decrement (--) Operators ใน C++

    พื้นฐาน ++ เพิ่ม 1 ให้ operand, -- ลด 1 จาก operand x = x + 1; // เทียบเท่า x++; x = x - 1; // เทียบเท่า x--; ทั้งคู่ใช้ได้ทั้ง Prefix (หน้า) และ Postfix (หลัง) ความแตกต่างสำคัญ: Prefix vs Postfix Prefix (++i): เพิ่มค่าก่อน แล้วคืนค่าใหม่ (increment แล้ว assign) Postfix (i++): คืนค่าเดิมก่อน แ

Total 6007 -คอมพิวเตอร์  FirstPage PreviousPage NextPage LastPage CurrentPage:6/301  20-คอมพิวเตอร์/Page Goto:1 2 3 4 5 6 7 8 9 10 11 12