المتغيرات والثوابت في البرمجة

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

ما هي الطريقة الصحيحة للاعلان عن متغير في لغة #C؟

  • اسم المتغير
  • نوع البيانات اسم المتغير (correct)
  • اسم المتغير نوع البيانات
  • نوع البيانات

ماذا يعني أن المتغيرات حساسة لحالة الأحرف في لغة #C؟

  • يمكن استخدام أي حالة من الأحرف في اسم المتغير
  • لا يمكن استخدام الأحرف الصغيرة في أسماء المتغيرات
  • التمييز بين الأحرف الكبيرة والصغيرة في اسم المتغير مهم (correct)
  • يجب أن يبدأ اسم المتغير بحرف كبير

أي من الخيارات التالية يعتبر اسم متغير غير صالح في لغة #C؟

  • _myVariable
  • 1myVariable (correct)
  • MyVariable
  • myVariable

ما هي الكلمة المفتاحية المستخدمة لتعريف ثابت في لغة #C؟

<p>const (B)</p> Signup and view all the answers

أي نوع من البيانات يستخدم لتخزين سلسلة من الأحرف في لغة #C؟

<p>string (A)</p> Signup and view all the answers

ما هو نوع البيانات الذي يخزن قيمة منطقية (صحيح أو خطأ) في لغة #C؟

<p>bool (B)</p> Signup and view all the answers

أي نوع من البيانات يستخدم لتخزين الأرقام الصحيحة في لغة #C؟

<p>int (A)</p> Signup and view all the answers

ما هو نوع البيانات الذي يخزن الأرقام العشرية في لغة #C؟

<p>float (B)</p> Signup and view all the answers

ماذا يحدث إذا حاولت تخزين قيمة من نوع بيانات أكبر في متغير من نوع بيانات أصغر؟

<p>يحدث خطأ في البرنامج (D)</p> Signup and view all the answers

ما هي القيمة الافتراضية للمتغير المنطقي (bool) إذا لم يتم تحديد قيمة له؟

<p>false (C)</p> Signup and view all the answers

ماذا تعني 'فترة حياة المتغير'؟

<p>المدة التي يبقى فيها المتغير محتفظاً بقيمته في الذاكرة (A)</p> Signup and view all the answers

ما هو 'نطاق المتغير'؟

<p>الأجزاء في البرنامج التي يمكنها الوصول إلى المتغير (C)</p> Signup and view all the answers

كيف يمكنك تحويل البيانات الرقمية إلى بيانات نصية في لغة #C؟

<p>باستخدام دالة ToString (C)</p> Signup and view all the answers

ماذا يحدث عند محاولة استخدام متغير لم يتم الإعلان عنه؟

<p>يحدث خطأ في وقت التشغيل (A)</p> Signup and view all the answers

ما هي المتغيرات المحلية؟

<p>المتغيرات التي يتم تعريفها داخل دالة أو كتلة برمجية (B)</p> Signup and view all the answers

ما هي المتغيرات العامة؟

<p>المتغيرات التي يمكن الوصول إليها من أي مكان في البرنامج (A)</p> Signup and view all the answers

عند تحويل قيمة من نوع بيانات عشري إلى نوع بيانات صحيح، ماذا يحدث للجزء العشري؟

<p>يتم تجاهله (B)</p> Signup and view all the answers

أي العمليات التالية تستخدم لدمج سلسلتين نصيتين في لغة #C؟

<ul> <li>(A)</li> </ul> Signup and view all the answers

لماذا نستخدم الثوابت في البرمجة؟

<p>لتخزين القيم التي لا تتغير خلال تنفيذ البرنامج (A)</p> Signup and view all the answers

ما هو الغرض من استخدام دالة Parse؟

<p>تحويل قيمة نصية إلى قيمة رقمية (C)</p> Signup and view all the answers

أي من هذه الأنواع يمكن أن يخزن True أو False؟

<p>bool (C)</p> Signup and view all the answers

ماذا يمثل المدى (Scope) الخاص بالمتغير؟

<p>الأجزاء في البرنامج التي يمكنها الوصول إلى المتغير. (D)</p> Signup and view all the answers

ماذا يحدث إذا قمت بتعريف متغيرين بنفس الاسم داخل نفس النطاق؟

<p>يحدث خطأ في وقت الترجمة. (D)</p> Signup and view all the answers

أي العمليات التالية تستخدم لزيادة قيمة متغير بمقدار واحد؟

<p>++ (A)</p> Signup and view all the answers

ماذا تفعل الدالة ToString()؟

<p>تحويل الأرقام إلى نص. (B)</p> Signup and view all the answers

أي من هذه الخيارات ليس نوع بيانات رقمي؟

<p>string (C)</p> Signup and view all the answers

ماذا يحدث إذا حاولت قسمة رقم على صفر؟

<p>يحدث خطأ في وقت التشغيل. (A)</p> Signup and view all the answers

ما هي القيمة الافتراضية للمتغير العددي (int) إذا لم يتم تحديد قيمة ابتدائية؟

<p>0 (B)</p> Signup and view all the answers

أي من هذه الخيارات هو طريقة صحيحة لتعريف متغير ثابت من النوع int باسم SIZE وقيمته 10؟

<p>const int SIZE = 10; (B)</p> Signup and view all the answers

في C#، ما هي الطريقة الصحيحة لتعريف متغير نصي باسم message يحتوي على القيمة Hello World؟

<p>string message = &quot;Hello World&quot;; (D)</p> Signup and view all the answers

ما هي نتيجة الكود التالي؟ int x = 5; x = x + 3; Console.WriteLine(x);

<p>8 (A)</p> Signup and view all the answers

أي نوع من البيانات هو الأنسب لتخزين عمر شخص؟

<p>int (B)</p> Signup and view all the answers

ماذا يحدث إذا حاولت جمع متغير من نوع string مع متغير من نوع int باستخدام عامل الجمع +؟

<p>سيتم تحويل المتغير <code>int</code> إلى <code>string</code> ودمجهما. (B)</p> Signup and view all the answers

ما هي الكلمة المفتاحية المستخدمة للإشارة إلى قيمة غير قابلة للتغيير بعد الإسناد الأولي؟

<p>readonly (B)</p> Signup and view all the answers

عند تعريف متغير داخل حلقة for، ما هو نطاقه؟

<p>الحلقة <code>for</code> فقط (C)</p> Signup and view all the answers

أي من العمليات التالية تقوم بإرجاع باقي القسمة؟

<p>% (C)</p> Signup and view all the answers

في C#، أي مما يلي يمثل طريقة صحيحة لتعريف متغير من النوع العشري (decimal) وتعيين قيمة له؟

<p>decimal price = 19.99m; (C)</p> Signup and view all the answers

Flashcards

المتغيرات (Variables)

حقول في الذاكرة لتخزين البيانات، قابلة للتغيير.

الثوابت (Constants)

حقول في الذاكرة بقيم ثابتة لا تتغير.

قاعدة أساسية في تسمية المتغيرات

يجب أن يبدأ بحرف هجائي.

حساسية حالة الأحرف (Case sensitive)

تعتبر الأحرف الكبيرة والصغيرة مختلفة

Signup and view all the flashcards

الإعلان عن المتغير

تحديد اسم ونوع المتغير لحجز مساحة في الذاكرة.

Signup and view all the flashcards

int

نوع بيانات للأرقام الصحيحة.

Signup and view all the flashcards

float

نوع بيانات للأرقام العشرية.

Signup and view all the flashcards

string

نوع بيانات للنصوص.

Signup and view all the flashcards

bool

نوع بيانات للقيم المنطقية (صح أو خطأ).

Signup and view all the flashcards

تخصيص قيمة للمتغير (Assign)

إعطاء قيمة للمتغير.

Signup and view all the flashcards

قاعدة أساسية في المتغيرات من النوع String

الرقمية تحتاج وضع القيمة بين علامتي تنصيص

Signup and view all the flashcards

طريقة استخدام المتغير

وضع قيمة للمتغير ثم استخدامها في متغير آخر

Signup and view all the flashcards

كيفية عرض قيمة المتغير للمستخدم

المتغير الذي يظهر لنا المستخدم

Signup and view all the flashcards

كيفية يتعامل الكمبيوتر مع المتغيرات

تخصيص قيمة للمتغيرات عن طريق الصيغ

Signup and view all the flashcards

المتغيرات المحلية (Local Variables)

المتغيرات التي يتم تعريفها داخل إجراء معين واستخدامها داخله فقط

Signup and view all the flashcards

متغيرات علي مستوي الملف أو النموذج

المتغيرات التي تكون متاحة لكل الإجراءات والوظائف

Signup and view all the flashcards

المتغيرات العامة (Global Variables)

إذا كان لديك أكثر من نافذة أو نموذج داخل مشروعك

Signup and view all the flashcards

تعريف الثوابت الخاصة

الاعلان عن المتغير ثم وضع const أمامه

Signup and view all the flashcards

التحويل بين أنواع البيانات

هي انواع مختلفة من البيانات وكل منها له مساحة محدده في الذاكرة يخزن فيها البيانات

Signup and view all the flashcards

إجراء Parse

اجراء لتحويل الحروف الي أرقام

Signup and view all the flashcards

الإجراء ToString

إجراء لتحويل الأرقام إلى حروف

Signup and view all the flashcards

Study Notes

Variables and Constants

  • Variables are named storage locations in memory that can hold different values during program execution.
  • Constants are named storage locations in memory that hold values that cannot be changed during program execution.
  • Variables can store numerical, character, or other types of data.
  • Variable contents can be altered at any time.
  • Constants hold fixed data values that cannot changed during program execution.
  • Examples of constants include a circle's area calculation where pi (π) is a constant value of 3.14.

Differentiating Variables and Constants

  • Variables and constants are differentiated by their mutability, variables can change, constants cannot.

Variable Naming Rules

  • Variable names must not start with a number.
  • Variable names must begin with a letter.
  • Variable names are case-sensitive.
  • The variable name starts with a letter.
  • Variable names cannot include spaces or special symbols.
  • Variable names must not be reserved words in C#.
  • It is possible to use the underscore character between the words

Data Types

  • Data type declarations allocate memory space for the specified type of data.
  • Common data types include integers, float, and strings.
  • NET allocates memory based on the data type.
  • There are signed integers to store both positive and negative numbers.
  • There are unsigned integers which store only positive values.

Integer Data Types

  • byte: Stores integers from 0 to 255 (1 byte).
  • sbyte: Stores integers from -128 to 127 (1 byte).
  • short: Stores integers from -32,768 to 32,767 (2 bytes).
  • ushort: Stores integers from 0 to 65,535 (2 bytes).
  • int: Stores integers from -2,147,483,648 to 2,147,483,647 (4 bytes).
  • uint: Stores integers from 0 to 4,294,967,295 (4 bytes).
  • long: Stores integers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (8 bytes).
  • ulong: Stores integers from 0 to 18,446,744,073,709,551,615 (8 bytes).

Floating Point Data Types

  • float: Stores floating-point numbers(4 bytes, 7 decimal digits).
  • double: Stores floating-point numbers (8 bytes, 16 decimal digits).
  • decimal: Stores floating-point numbers (16 bytes, 29 decimal digits).

Declaring Variables

  • Variable declaration involves specifying the data type and name.
Datatype VariableName;
int streetNum;
  • Multiple variables can be declared in one line.
int ax, bx, cx;

Strings and Chars Data Types

  • string: Stores a sequence of text from multiple characters.
  • char: Stores a single character (2 bytes).
string address;

Boolean Data Type

  • bool: Stores either true or false values.
bool bx;
  • The default value is false.

Working with Variables

  • Assigning a value is called assignment.

Assigning Values to Variables

  • Assign a value to a variable
int xx=90;
  • Assign a value after declaring
int xx;
xx=90;

How Computers Handle Variables

  • Assignment statements assign value.
  • When you use the same name on both sides the computer computes the right side and overrides the left side.

Variable Scope

  • Local Variables declared inside a method.
  • Model Variables declared in the model, where they are kept until disposal.
  • Global Variables are available to all Models.

Local Variables

  • Declared inside a particular procedure or block of code.
  • Use is restricted to the block in which declaration took place.

Model Variables

  • Declared within the Form creation part.
  • Visible to all actions within the form.
  • Persist in memory until the form closes.

Global Variables

  • Usable in every model.
  • Declared inside a class.

Constants

  • Constants values cannot be changed while the program is running.
  • Two types: those defined within C#.NET and those defined by the programmer.
  • To declare constants use const data type such as float.

Programmer Defined Constants

  • These are defined within the project to be used as project specific constants.

Data Type Conversions

  • C# provides type conversion between variables.
  • A value placed between quotation marks "" will always be text.
  • C#.Net treats text differently than numbers.

Parsing

  • Use Parsed data when user inputs data is automatically stored as text (strings).
int xx;
xx= int.Parse(textBox1.Text) +int.Parse(textBox2.Text);
textBox3.Text = xx.ToString();
  • Used when converting strings to numeric values example converting temperature from Celsius to Fahrenheit.

Converting Numbers to Strings

  • Use .ToString();
Label1.Text = My_salary.ToString();

Numeric Data Conversions

  • Type must be converted when converting between short and long, you can convert shorts into longs because it is going from smaller to larger bytes.
  • Errors will occur when going from larger type like Long into Short.
  • Operations for converting follow the Convert class.

Conversion Functions

  • Convert.ToInt16
  • Convert.ToInt32
  • Convert.ToInt64
  • Convert.ToDecimal
  • Convert.ToSingle
  • Convert.ToDouble
  • Convert.ToByte
B1= Convert.ToDecimal(A1);
B2 = Convert.ToInt32(A2);

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser