(Exercise Unit No. 09)
Q.1. what is an identifier? Give some examples of identifier.
The identifier is the name given to the variable, constants, type, function or label in the
program.
نشکنفایلبیلوکدایاجاتےہ۔،مسق،لقتسم،انشتخدننکہوہانمےہوجرپورگامںیمریغتم
It may consist of any number of characters.
ہیرحوفیکیسکیھبدعتادرپلمتشموہاتکسےہ۔
But the first 31 characters are Significant to C compiler.
رمبترکےنواےلےکےیلامہںیہ۔Cرحوف31نکیلےلہپ
Some examples of identifiers are Student_Age, ltem2O and Sum etc.
وریغہںیہ۔eAeاورOeSe2l،eeA_SnedutSانشتخدننکاگنیکھچکاثمںیل
Q.2. Write the legal characters for an identifier.
The legal characters for an identifier include Upper alphabets from A to Z lower alphabets
from a to z, digits from 0 to 9 and the underscore character.
کتےکدنہےساوراڈنروکسررکرٹکیاشلمںیہ۔9ےس0،کتےکرحوفیجہتzےسaکتےکاورپیرحوفیجہتZےسuانشتخدننکہےکاقونینرحوفںیم
Q.3. How many types of identifiers are used in C language?
There are two types of identifiers in C language.
زابنںیمانشتخدننکاگنیکدوںیمسقںیہ۔C
These are standard identifiers and user-defined identifiers.
ہیایعمریانشتخدننکاگناوراصرفیکواضتحرکدہانشتخدننکہںیہ۔
Q.4. What is standard identifier? Give Some examples.
A type of identifier that has special meaning in C is known as standard identifier.
ںیماخصینعمریتھکےہایعمریانشتخدننکہےکوطررپاجاناجاتےہ۔Cانشتخدننکہیکاکیمسقوج
C cannot use a standard identifier for its original purpose if it is redefined.
ایعمریانشتخدننکہوکاےنپالصدصقمےکےیلاامعتسلںیہنرکاتکسارگاسیکدوابرہواضتحیکیئگوہ۔C
printf and scanf are examples of standard identifiers.
ایعمریانشتخدننکاگنیکاثمںیلںیہ۔fnanpاورftnnep
Q.5. What is user-defined identifier? Give Some examples
The type of identifier that is defined by the programmer is known as user-defined identifier.
انشتخدننکہیکمسقوجرپورگارمےکذرہعیایبنیکاجیتےہاےساصرفیکواضتحدشہانشتخدننکہےکانمےساجاناجاتےہ۔
The user-defined identifiers are used to store data and program results.
اصرفےکایبنرکدہانشتخدننکاگنوکڈاٹیاوررپورگامےکاتنجئوکذریخہرکےنےکےیلاامعتسلایکاجاتےہ۔
Some examples of user-defined identifiers are num, age, marks etc.
اشنانتوریغہںیہ۔،رمع،اصرفےکایبنرکدہانشتخدننکاگنیکھچکاثمںیلربمن
Q.6. What is keyword? Give Some examples.
Keyword is a word in C language that has a predefined meaning and purpose.
زابنںیماکیااسیظفلےہسجاکےلہپےسےطدشہینعماوردصقموہاتےہ۔Cدیلکیظفل
It defined by the developer of the language.
اسیکرعتفیزابنےک ل پ ر
ڈویےنیکےہ۔
It cannot be changed or redefined by the user.
اےساصرفےکذرہعیدبتلیاییئنواضتحںیہنیکاجیتکسےہ۔
Composed by: M. Umair Nasir
, Computer# Unit No. 09 2
Some examples of keywords are if, while, int and const.
ںیہ۔nsnfeاورnp, ,enOS, nneولطمہباظاف یکھچکاثمںیل
Q.7. How can you differentiate keyword from identifier?
Keywords are the words that have predefined meaning and purpose.
دیلکیاظاف وہاظاف ںیہنجےکینعماوردصقمےلہپےسنیعتموہےتںیہ۔
The identifiers are defined by the user.
انشتخدننکاگنیکرعتفیاصرفےکذرہعییکاجیتےہ۔
Q.8. What is variable? Why is it used in programs?
A variable is a named memory location or memory cell.
اکیریغتماکیانزمدومیمریاقممایومیمریلیسےہ۔
It is used to store programs input data and its computational results
ی ن لduring execution.
ل
اساکاامعتسلرپورگاومںےکانٹپڈاٹیاوراسےکویپمکٹاتنجئوکدلمعرآدمےکدورانذریخہرکےنےکےیلایکاجاتےہ۔
The value of variable may change during the execution of the program.
رپورگامےکافنذےکدورانریغتمیکدقردبتلیوہیتکسےہ۔
However, the name of variable cannot be changed.
ریغتماکانمدبتلیںیہنایکاجاتکس۔،اتمہ
Q.9. Define variable declaration.
The process of specifying the variable name and its type is called variable declaration.
ریغتماکانماوراسیکمسقاتبےنےکلمعوکریغتماالعہیماہکاجاتےہ۔
Q.10. Is it compulsory to declare all variables in C program?
Yes, it is compulsory to declare all variables before they are used in C program.
یسرپورگامںیماامعتسلوہےنےسےلہپامتمریغتماتاکاالعنرکانالزیمےہ۔،یجاہں
The compiler gives an error if an undeclared variable is used in a program. ل
اپمکئاکیاریرداتیےہارگیسکرپورگامںیمریغاالعہینریغتماامعتسلوہاتےہ۔
ر
Q.11. Why is C known as strongly typed language?
It means that a variable must always be declared before it can be used in a program.
اساکبلطمہیےہہکیسکرپورگامںیماامعتسلوہےنےسےلہپریغتماکہشیمہاالعنایکاجاناچےیہ۔
The compiler gives an error if an undeclared variable is used in a program. ل
اپمکئاکیاریرداتیےہارگیسکرپورگامںیمریغاالعہینریغتماامعتسلوہاتےہ۔
ر
Q.12. What is specified in variable declaration?
The variable name and its data type is specified in variable declaration.
ریغتماکانماوراسےکڈاٹییکمسقریغتماالعہیمںیمایبنیکیئگےہ۔
The variable name refers to the memory location of the variable.
ریغتماکانمریغتمیکومیمرییکہگجےسرمادےہ۔
The data type indicates the type of data that can be stored in variable.
ڈاٹییکمسقڈاٹییکمسقیکاشنہد یرکیتےہ ےسریغتمںیمظوفح ایکاجاتکسےہ۔
Q.13. How are variables declared? Give two examples.
The variables in C language are declared by specifying the variable name and its data type.
زابنںیمریغتماتاکاالعنریغتمےکانماوراسےکڈاٹییکمسقوکاتبرکایکاجاتےہ۔C
Two examples of declaring variable are int marks; and float average;
امرسک; اورولفٹاوطس؛ ںیہ۔nneریغتماکاالعنرکےنیکدواثمںیل
Composed by: M. Umair Nasir
, Computer# Unit No. 09 3
Q.14. How can you declare multiple variables of same data type in one line?
Multiple variables of same data type can be declared in one line by writing variable names
separated with commas.
اکی یڈاٹییکمسقےکدعتمدریغتماتاکاالعناکیالنئںیمریغتمانومںوکوکامےساگلرکےکھکلرکایکاجاتکسےہ۔
An example is as follows: int a,b,c;
; nne a ,t,n:اکیاثملدنمرہجذلیےہ
Q.15. Differentiate between declaring and defining a variable.
The variable declaration specifies the name and type of the variable to the compiler.
ریغتماالعہیمرمبترکےنواےلےکےیلریغتماکانماورمسقاتباتےہ۔
It does not set aside memory location.
ہیومیمرییکہگجوکاگلںیہنرکاتےہ۔
The variable definition specifies the name and type of the variable as well as sets aside
memory location to store the data in the variable.
ریغتمیکرعتفیریغتمےکانماورمسقیکواضتحرکیتےہاوراسھت یریغتمںیمڈاٹیوکذریخہرکےنےکےیلومیمرییکہگجوکاگلرکیتےہ۔
Q.16. Define variable initialization? How is a variable initialized?
The process of assigning a value to a variable at the time of declaration is known as variable
initialization.
االعنےکوتقریغتموکدقروفتضیرکےنےکلمعوکریغتمادتباءےکانمےساجاناجاتےہ۔
The equal sign = is used to initialize a variable.
اسمویاشنن=ریغتموکرشوعرکےنےکےیلاامعتسلایکاجاتےہ۔
Variable name is written on left side and the value is written on the right side of equal sign.
ریغتماکانمابںیئرطفاھکلاجاتےہاوردقرربارباشننےکداںیئرطفیھکلاجیتےہ۔
Q.17. What is garbage value?
The compiler automatically allocates the required memory for the variable when it is
declared.
رمبترکےنواالوخدوخبدریغتمےکےیلولطمہبومیمریصتخمرکاتےہبجاساکاالعنایکاجاتےہ۔
The memory location may already contain some data that is meaningless for the program.
ومیمرییکہگجںیمےلہپےس یھچکڈاٹیوہاتکسےہوجرپورگامےکےیلےبینعمےہ۔
This meaningless data is known as garbage value.
اسےبینعمڈاٹیوکردییکتمیقےکوطررپاجاناجاتےہ۔
Q.18. Why is it good to initialize a variable?
The variable may have garbage value if it is not initialized.
ریغتمںیمردییکتمیقوہیتکسےہارگاےسرشوعںیہنایکایگےہ۔
It may produce unexpected results in some computations.
ہیھچکاسحابتںیمریغوتمعقاتنجئدیپارکاتکسےہ۔
All variables should be initialized to avoid this problem.
اسےلئسمےسےنچبےکےیلامتمریغتماتوکرشوعایکاجاناچےیہ۔
Q.19. Write any three rules for declaring variables in C.
The first character of variable must be a letter or underscore.
ریغتماکالہپرحفاکیرحفایاڈنروکسروہاناچےیہ۔
Composed by: M. Umair Nasir