ASSIGNMENT I Programming Fundamentals Course Supervisor

ASSIGNMENT I
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
examples.
Ans: VARIABLE:
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.
EXAMPLES:
? Declaration
;
int a;
? Definition
=;
a=10;
? Usage

a=a+1; //increments the value of a by 1
ASSIGNMENT:
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.
EXAMPLES:
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
bal=;balance;
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:
value=*balance;
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
screen.
Example:
#include
#include
int main()
{
printf(“%c”, getch());
return 0;
}
getche():
getche() is a nonstandard function that gets a character from the keyboard, echoes to
screen.
Example:
#include
#include
// 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.
Ans: PROGRAM:
#include
#include
int main ()
{ float Subject1_Marks = 0;
float Subject2_Marks = 0;

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

float Subject3_Marks = 0;
float Subject4_Marks = 0;
float Subject5_Marks = 0;
float Total_Marks = 0;
printf(“Enter the marks for subject 1 : “);
scanf(“%f”,;Subject1_Marks);

printf(“\nEnter the marks for subject 2 : “);
scanf(“%f”,;Subject2_Marks);

printf(“\nEnter the marks for subject 3 : “);
scanf(“%f”,;Subject3_Marks);

printf(“\nEnter the marks for subject 4 : “);
scanf(“%f”,;Subject4_Marks);

printf(“\nEnter the marks for subject 5 : “);
scanf(“%f”,;Subject5_Marks);
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.”);
getch();}
OUTPUT:
Q6. Write a program using == , ++ , % ,

x

Hi!
I'm Martha!

Would you like to get a custom essay? How about receiving a customized one?

Check it out