Exam 01
ลำดับการทำงานของ   Operator ลำดับความสำคัญจากสูงไปต่ำ โอเปอเรเตอร์ ( ) ++, -- -( เครื่องหมายลบหน้าตัวเลข ) * ,  /  , % +  ,  -
จากโปรแกรมด้านล่างนี้ คำตอบที่ได้ ค่า  i  คืออะไร  #include<iostream.h> void main( ) { int  i, j=5,k; i = j+(k=3)*5; cout<< i <<endl; } i = j+(k=3)*5; i = 5+(3*5); i = 3+15; i=20 ;
จงหาค่าที่คำนวณได้ดังต่อไปนี้ (-5*(192/3)+7)-4%10*2 (-5*( 64 )+7)-4%10*2 ( 320  +7)-4%10*2 ( -313 )- 4 *2 -313- 8  =-321
กำหนดให้  a = 7  b=5  c=3  d=6 2.2  -10+(++a)-7+3*2%7*2  = 3 2.3  ++b+d--%2*(++c*4-1)/2  = 6 2.4  2*5%3/2*(c++/2*d---8)  = 0 จงหาค่าที่คำนวณได้ดังต่อไปนี้
กำหนดให้  a = 7  b=5  c=3  d=6 2.2  -10+(++a)-7+3*2%7*2 2.3  ++b+d--%2*(++c*4-1)/2 2.4  2*5%3/2*(c++/2*d---8) จงหาค่าที่คำนวณได้ดังต่อไปนี้ กำหนดให้  a = 7  b=5  c=3  d=6 -10+(++ 7 )-7+3*2%7*2 -10+( 8 )-7+ 6 *2 -10+( 8 )-7+ 12 -2 -7+ 12  =3
กำหนดให้  a = 7  b=5  c=3  d=6 2.2  -10+(++a)-7+3*2%7*2 2.3  ++b+d--%2*(++c*4-1)/2 2.4  2*5%3/2*(c++/2*d---8) จงหาค่าที่คำนวณได้ดังต่อไปนี้ กำหนดให้  a = 7  b=5  c=3  d=6   ++b+d--%2*(++c*4-1)/2   ++5 + 6 --%2*(++ 3 *4-1)/2   6 + 6 --%2*( 4 *4-1)/2  =>>  6--%2 =0 ( ทำ  6%2  ก่อน แล้วค่อยทำ  6++  หลังจากทำคำสั่งทั้งหมดเสร็จ )   6 + 0 *( 15 )/2   6-0/2  =  6
กำหนดให้  a = 7  b=5  c=3  d=6 2.2  -10+(++a)-7+3*2%7*2 2.3  ++b+d--%2*(++c*4-1)/2 2.4  2*5%3/2*(c++/2*d---8) จงหาค่าที่คำนวณได้ดังต่อไปนี้ กำหนดให้  a = 7  b=5  c=3  d=6 2*5%3/2*(c++/2*d---8) ( c++  และ  d— จะทำหลังจากคำสั่งนี้ทำเสร็จ  ) 2*5%3/2*( 3 /2* 6 -8) 10 %3/2*( 1 * 6 - 7 ) 1 /2*( -1 ) 0*(-1)  = 0
#include<iostream.h>  void main(){  int a=9,b=6,c=0; c = (a++)+(++b); cout <<  a <<  &quot;  &quot;  << b << &quot;  &quot; << c<< endl;  c= (--a)-(--b); cout  <<  a << &quot;  &quot; <<  b  << &quot;  &quot; << c << endl;  c=++a; c=c-b--; c=c+--a; c=c-++b; cout <<  a << &quot;  &quot; << b <<  &quot;  &quot; << c <<endl; } 10  7  16 9  6  3 6  3 5  4 9  6  7
คำสั่งในข้อใดที่ให้ผลลัพธ์เหมือนกัน  (i) a = 6 + 10 * 2 – 2 * 3;  =  20  (ii) a = 7 / 4 * 8 + 4 * 3; = 20 (iii) a = 5 / 3 * 3 / 5 + 3 + 4 * 4; = 19;
จากโปรแกรมถ้าป้อนค่า  9  เข้าไปผลลัพธ์ที่ได้ออกมาคืออะไร void main(){ int  n;  cin>>n;  if(n <= 8)  n=n+1;  n = n+2; if ( n>= 11) n=n-2;  n = n-1; cout<< n<<endl;  }   n=9 (9<=8 ?)  No=> n=n+2   n= 11 n>=11?  Yes =>n=n-2 n=9  n=n-1 = 8
#include<iostream.h> void main(){ int  inputNumber, i; do { cout<<&quot;Enter Positive Number between 2  to 20 >> &quot; ; cin>> inputNumber;  } while ( inputNumber<2 || inputNumber>20 );   for( i=1;i<=12;i++ ){ cout << i << &quot; * &quot;<<inputNumber<<&quot; = &quot;  << i*inputNumber<< endl; } }
Integer  เลขจำนวนเต็ม Type Signed Byte Lower upper shot int signed 2 (16 bit) -32,768 32,768 unsigned 2 (16 bit) 0 65535 Int (16bits) signed 2 (16 bit) -32,768 32,768 unsigned 2 (16 bit) 0 65535 Int (32 bits) signed 4 (32 bit) -2,147,483,648 2,147,483,647 unsigned 4 (32 bit) 0 4,294,967,295 long int signed 4 (32 bit) -2,147,483,648 2,147,483,647 unsigned 4 (32 bit) 0 4,294,967,295
Float  เลขทศนิยม -38 -308 -4932 38 308 4932 Character  ชนิดข้อมูลแบบอักษร ชนิดข้อมูลแบบอักษร คือข้อมูลประเภท  char  ซึ่งจะเก็บได้  1  ตัวอักษร เครื่องจะทำ การเก็บอยู่ในรูปของรหัส  Ascii   เช่น   A = 65  หรือ  0110 0001 Type Byte Lower Upper float 4 3.4 x 10 3.4 x 10 double 8 1.7x10 1.7x10 long double 10 3.4x10 3.4x10
Ascii code
Ascii code
การแปลงข้อมูล Implicit Type Conversion การแปลงชนิดของข้อมูลให้อยู่ในรูปแบบที่เหมาะสมโดยอัตโมมัติ ชนิดของข้อมูล Long double นัยสำคัญสูงสุด นัยสำคัญต่ำสุด Double Float Unsigned long int Long in  Unsigned int Int Short char
Implicit Conversion ในนิพจน์หนึ่งๆจะประกอบด้วยชนิดของข้อมูลหลายหลายประเภท ภาษาซีจะทำการแปลงชนิดของข้อมูลให้โดยอัตโนมัติ โดยที่ชนิดที่มีนัยสำคัญต่ำกว่าจะถูกแปลงให้เป็นชนิดข้อมูลที่มีนัยสำคัญสูงกว่าเสมอ เช่น C = Int A  + float B การบวกตัวแปร  A  ที่มีชนิดเป็น  int  กับ  B  ที่มีชนิด เป็น  float  นั้นไม่สามารถทำได้ทันทีเพราะว่าเป็นตัวแปรต่างชนิดกัน แต่ภาษาซีจะทำการ แปลงชนิดของข้อมูลจาก  int  ไปเป็น  float   ( จากนัยต่ำกว่าไปสูงกว่า )  แล้วจึงทำการบวก โดยค่าซีที่ได้จะมีชนิดของข้อมูลเป็น  float นิพจน์ การแปลงชนิดข้อมูล char + float แปลง  char  ไปเป็น  float unsigned int – long int แปลง  unsigned int  ไปเป็น  long int float * double แปลง  float  ไปเป็น  double Int/ long double แปลง  int  ไปเป็น   long double (short + long) / double แปลง   short  ไปเป็น  long  ( ทำในวงเล็บก่อน )  จากนั้น แปลงค่าจาก  long  ให้เป็น  double

1 test

  • 1.
  • 2.
    ลำดับการทำงานของ Operator ลำดับความสำคัญจากสูงไปต่ำ โอเปอเรเตอร์ ( ) ++, -- -( เครื่องหมายลบหน้าตัวเลข ) * , / , % + , -
  • 3.
    จากโปรแกรมด้านล่างนี้ คำตอบที่ได้ ค่า i คืออะไร #include<iostream.h> void main( ) { int i, j=5,k; i = j+(k=3)*5; cout<< i <<endl; } i = j+(k=3)*5; i = 5+(3*5); i = 3+15; i=20 ;
  • 4.
  • 5.
    กำหนดให้ a= 7 b=5 c=3 d=6 2.2 -10+(++a)-7+3*2%7*2 = 3 2.3 ++b+d--%2*(++c*4-1)/2 = 6 2.4 2*5%3/2*(c++/2*d---8) = 0 จงหาค่าที่คำนวณได้ดังต่อไปนี้
  • 6.
    กำหนดให้ a= 7 b=5 c=3 d=6 2.2 -10+(++a)-7+3*2%7*2 2.3 ++b+d--%2*(++c*4-1)/2 2.4 2*5%3/2*(c++/2*d---8) จงหาค่าที่คำนวณได้ดังต่อไปนี้ กำหนดให้ a = 7 b=5 c=3 d=6 -10+(++ 7 )-7+3*2%7*2 -10+( 8 )-7+ 6 *2 -10+( 8 )-7+ 12 -2 -7+ 12 =3
  • 7.
    กำหนดให้ a= 7 b=5 c=3 d=6 2.2 -10+(++a)-7+3*2%7*2 2.3 ++b+d--%2*(++c*4-1)/2 2.4 2*5%3/2*(c++/2*d---8) จงหาค่าที่คำนวณได้ดังต่อไปนี้ กำหนดให้ a = 7 b=5 c=3 d=6 ++b+d--%2*(++c*4-1)/2 ++5 + 6 --%2*(++ 3 *4-1)/2 6 + 6 --%2*( 4 *4-1)/2 =>> 6--%2 =0 ( ทำ 6%2 ก่อน แล้วค่อยทำ 6++ หลังจากทำคำสั่งทั้งหมดเสร็จ ) 6 + 0 *( 15 )/2 6-0/2 = 6
  • 8.
    กำหนดให้ a= 7 b=5 c=3 d=6 2.2 -10+(++a)-7+3*2%7*2 2.3 ++b+d--%2*(++c*4-1)/2 2.4 2*5%3/2*(c++/2*d---8) จงหาค่าที่คำนวณได้ดังต่อไปนี้ กำหนดให้ a = 7 b=5 c=3 d=6 2*5%3/2*(c++/2*d---8) ( c++ และ d— จะทำหลังจากคำสั่งนี้ทำเสร็จ ) 2*5%3/2*( 3 /2* 6 -8) 10 %3/2*( 1 * 6 - 7 ) 1 /2*( -1 ) 0*(-1) = 0
  • 9.
    #include<iostream.h> voidmain(){ int a=9,b=6,c=0; c = (a++)+(++b); cout << a << &quot; &quot; << b << &quot; &quot; << c<< endl; c= (--a)-(--b); cout << a << &quot; &quot; << b << &quot; &quot; << c << endl; c=++a; c=c-b--; c=c+--a; c=c-++b; cout << a << &quot; &quot; << b << &quot; &quot; << c <<endl; } 10 7 16 9 6 3 6 3 5 4 9 6 7
  • 10.
    คำสั่งในข้อใดที่ให้ผลลัพธ์เหมือนกัน (i)a = 6 + 10 * 2 – 2 * 3; = 20 (ii) a = 7 / 4 * 8 + 4 * 3; = 20 (iii) a = 5 / 3 * 3 / 5 + 3 + 4 * 4; = 19;
  • 11.
    จากโปรแกรมถ้าป้อนค่า 9 เข้าไปผลลัพธ์ที่ได้ออกมาคืออะไร void main(){ int n; cin>>n; if(n <= 8) n=n+1; n = n+2; if ( n>= 11) n=n-2; n = n-1; cout<< n<<endl; } n=9 (9<=8 ?) No=> n=n+2 n= 11 n>=11? Yes =>n=n-2 n=9 n=n-1 = 8
  • 12.
    #include<iostream.h> void main(){int inputNumber, i; do { cout<<&quot;Enter Positive Number between 2 to 20 >> &quot; ; cin>> inputNumber; } while ( inputNumber<2 || inputNumber>20 ); for( i=1;i<=12;i++ ){ cout << i << &quot; * &quot;<<inputNumber<<&quot; = &quot; << i*inputNumber<< endl; } }
  • 13.
    Integer เลขจำนวนเต็มType Signed Byte Lower upper shot int signed 2 (16 bit) -32,768 32,768 unsigned 2 (16 bit) 0 65535 Int (16bits) signed 2 (16 bit) -32,768 32,768 unsigned 2 (16 bit) 0 65535 Int (32 bits) signed 4 (32 bit) -2,147,483,648 2,147,483,647 unsigned 4 (32 bit) 0 4,294,967,295 long int signed 4 (32 bit) -2,147,483,648 2,147,483,647 unsigned 4 (32 bit) 0 4,294,967,295
  • 14.
    Float เลขทศนิยม-38 -308 -4932 38 308 4932 Character ชนิดข้อมูลแบบอักษร ชนิดข้อมูลแบบอักษร คือข้อมูลประเภท char ซึ่งจะเก็บได้ 1 ตัวอักษร เครื่องจะทำ การเก็บอยู่ในรูปของรหัส Ascii เช่น A = 65 หรือ 0110 0001 Type Byte Lower Upper float 4 3.4 x 10 3.4 x 10 double 8 1.7x10 1.7x10 long double 10 3.4x10 3.4x10
  • 15.
  • 16.
  • 17.
    การแปลงข้อมูล Implicit TypeConversion การแปลงชนิดของข้อมูลให้อยู่ในรูปแบบที่เหมาะสมโดยอัตโมมัติ ชนิดของข้อมูล Long double นัยสำคัญสูงสุด นัยสำคัญต่ำสุด Double Float Unsigned long int Long in Unsigned int Int Short char
  • 18.
    Implicit Conversion ในนิพจน์หนึ่งๆจะประกอบด้วยชนิดของข้อมูลหลายหลายประเภทภาษาซีจะทำการแปลงชนิดของข้อมูลให้โดยอัตโนมัติ โดยที่ชนิดที่มีนัยสำคัญต่ำกว่าจะถูกแปลงให้เป็นชนิดข้อมูลที่มีนัยสำคัญสูงกว่าเสมอ เช่น C = Int A + float B การบวกตัวแปร A ที่มีชนิดเป็น int กับ B ที่มีชนิด เป็น float นั้นไม่สามารถทำได้ทันทีเพราะว่าเป็นตัวแปรต่างชนิดกัน แต่ภาษาซีจะทำการ แปลงชนิดของข้อมูลจาก int ไปเป็น float ( จากนัยต่ำกว่าไปสูงกว่า ) แล้วจึงทำการบวก โดยค่าซีที่ได้จะมีชนิดของข้อมูลเป็น float นิพจน์ การแปลงชนิดข้อมูล char + float แปลง char ไปเป็น float unsigned int – long int แปลง unsigned int ไปเป็น long int float * double แปลง float ไปเป็น double Int/ long double แปลง int ไปเป็น long double (short + long) / double แปลง short ไปเป็น long ( ทำในวงเล็บก่อน ) จากนั้น แปลงค่าจาก long ให้เป็น double