Sally Fitzgibbons Foundation

Beginning the Academic Essay

Programming Fundamentals
Course Supervisor: Syeda Nazia Ashraf
Name: Abdul Salam
Roll No: CSC-18F-029
Batch: CS1D (Evening)
Q1: What do you mean by variable definition and variable assignment? Give
Variables may be the most fundamental aspect of any computer language. A
variable is a space in the computer’s memory set aside for a certain kind of data and given a
name for easy reference. Variables are used so that the same space in memory can hold
different values at different times. Variables are data that will keep on changing.
? Declaration
int a;
? Definition
? Usage

a=a+1; //increments the value of a by 1
An assignment operator is the operator used to assign a new value to a variable,
property, event or indexer element in C# programming language Unlike in C++,
assignment operators in C# cannot be overloaded directly, but the user-defined types can
overload the operators like +, -, /, etc.
C = A + B will assign the value of A + B to C
Q2: Differentiate between \r, \n, \t, \f.
Ans: \r is use for carriage return.
\n is use for new line.
\t is use for horizontal tab.
\f is use for form feed, page eject, page or section separator.
Q3: What is the purpose of Pointer operators (; and *) and Member selection operator
(. and -;).
Ans : Pointer operators (; and *):
There are two special operators that are used with pointers * and ;. The ; is a unary
operator that returns the memory address of its operand, for example
puts into bal the memory address of the variable balance. This address is the location of the
variable in the computer’s internal memory. It has nothing to do with the value of balance. The
statements can be verbalized as bal receives the address of balance. This operator was used
previously in the functions section.
The second operator is *, and it is a complement of &. It is a unary operator that returns the value
of the variable at the address specified by its operand. Consider the example below:
This operation will balce the value of balance into value.
Member selection operator (. and ->):
This syntax is used to select a data member or a member function given a pointer
to an object (->) or an object (.) Selecting a data member means getting direct access to a
members data, at most objects won’t allow that as it breaks the hiding (or encapsulation) of
its data. Selecting a member function means calling that function (i.e. passing the object a
message). To pass a message to an object given a pointer to it requires the -; operator.
Q4: Differentiate between getch() and getche() with examples.
Ans: getch():
getch() is a nonstandard function that gets a character from keyboard, does not echo to
int main()
printf(“%c”, getch());
return 0;
getche() is a nonstandard function that gets a character from the keyboard, echoes to
// Example for getche() in C
int main()
printf(“%c”, getche());
return 0;}
Q5: Write a program which takes user marks for 5 subjects and then calculate total
marks obtained by user.
int main ()
{ float Subject1_Marks = 0;
float Subject2_Marks = 0;

float Subject3_Marks = 0;
float Subject4_Marks = 0;
float Subject5_Marks = 0;
float Total_Marks = 0;
printf(“Enter the marks for subject 1 : “);

printf(“\nEnter the marks for subject 2 : “);

printf(“\nEnter the marks for subject 3 : “);

printf(“\nEnter the marks for subject 4 : “);

printf(“\nEnter the marks for subject 5 : “);
Total_Marks = Subject1_Marks + Subject2_Marks + Subject3_Marks + Subject4_Marks
+ Subject5_Marks;

printf(“\nTotal marks obtained : %.2f”, Total_Marks);
printf(“\n\nPress any key to exit.”);
Q6. Write a program using == , ++ , % ,

Post Author: admin