College Papers

PROGRAMMING FUNDAMENTALS ASSIGNMENT NO 01 MUHAMMAD YASIR CSC-18F-058 MISS SYEDA NAZIA ASHRAF Q1

PROGRAMMING FUNDAMENTALS
ASSIGNMENT NO 01
MUHAMMAD YASIR
CSC-18F-058
MISS SYEDA NAZIA ASHRAF
Q1. What do you mean by variable definition and variable assignment? Give examples.

VARIABLE DEFINITION:
Variable definition means that telling the compiler to search as well as allocate certain amount of memory for that variable which we define. It also means that which we assign it in a certain value and we also say that the variable will assign some value to it.

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


order now

Example:
int a=5,b=10;//assign and define in program
Here we define the assign value which are a=5 and b=10.

VARIABLE ASSIGNMENT:
Variable Assignment means that telling the compiler that you need that variable in your C Program, it is just like telling the compiler that we are deciding to use that variable which is defined in somewhere either in the same file. It is easily say that compiler to allocate memory for the variable and specify its properties. It will identity the datatype of the identifier.

Example:
Int a,b;//assign variables in program
Q2. Differentiate between
,
, , f.

: It is called carriage return. It will move the cursor to the left side of the screen but will not move down a line.

Example:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“hello every
one”);
getch();
}

:It is call new line which means that the sentence should start in a new line when we compile in C language.

Example:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“hello
world”);
getch();
}

:It is called horizontal tab which means that when we want to get few spaces without pressing Space Key, so we use escape sequence which is horizontal tab, so it gives few spaces in C program.

Example:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“hello world”);
getch();
}

fIt is called form feed when we use form feed ( f ) in C program so when we compile it shows a female sign.

Example:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
printf(“hello fworld”);
getch();
}

Q3. What is the purpose of Pointer operators (& and *) and Member Selection operator (. And ->)
Pointer Operators:
There are two types of pointer operators which are “& “and “* “.

&
The & is an address operator that gives address of variables or the memory location in same file.

Example:
a=&b
puts into add the memory address of the variable addition. The address is the location of the variable in RAM. It has nothing to do with the value of addition. the statements/words can be reminded as add receives the address of addition.

*
The * is valued operator. It gives valued stored at address. It can be defined as that returns the value of the variable at the address is given by operator. It is also known as Indirection.

Example:
c=*b
This operator will addition the value of addition into total.

#include<stdio.h>
#include<conio.h>
void main(void)
{
int* a;
int b;
clrscr();
b=1;
printf(“Address of b= %d
“,&b);
printf(“Value of b= %d

“,b);
//& takes the address of b, here now a==&b, so *a==b a=&b;
printf(“Address of a= %d
“,a);
printf(“Content of a= %d

“,*a);
getch();
}

Member Selection:
The dot member selection operator (.) is preceded by an object’s name or with a reference to an object to access the object’s members. The arrow member selection operator (->) is preceded by a pointer to an object to access the object’s members.

Q4. Differentiate between getch() and getche() with examples.

Getch();
The getch() means get character. This function is used to get a single just only single character to input from the programmer during the C program. It also wait the output to stay on a display until user pressed any key from the keyboard.

Example:
#include;stdio.h;
#include;conio.h;
void main(void)
{
clrscr();
char a;
printf(“Enter Character=
“);
a=getch();
printf(“The character from user= %c
“,a);
getch();
}

Getche():
Getche means get character echo. It is also used to get a character from the programmer. When this function is executed, the character entered by the programmer is shown on the screen if programmer did not press enter key.

Example:
#include;stdio.h;
#include;conio.h;
void main(void)
{
clrscr();
char a;
printf(“Enter Character= “);
a=getche();
printf(”
The character from user= %c
“,a);
getch();
}

Q5. Write a program which takes user marks for 5 subjects and then calculate total marks obtained by user.

#include;stdio.h;
#include;conio.h;
void main(void)
{
int num1,num2,num3,num4,num5,add;
clrscr();
printf(”
MATHEMATICS= “,num1);
scanf(“%d”,;num1);
printf(”
PHYSICS= “,num2);
scanf(“%d”,;num2);
printf(”
COMPUTER= “,num3);
scanf(“%d”,;num3);
printf(”
ENGLISH= “,num4);
scanf(“%d”,;num4);
printf(”
URDU= “,num5);
scanf(“%d”,;num5);
{
add=num1+num2+num3+num4+num5;
}
printf(”

TOTAL MARKS OBTAINED OF ALL SUBJECT= %d”,add);
getch();
}

Q6. Write a program using ==, ++, %, ;= operators.

#include;stdio.h;
#include;conio.h;
void main(void)
{
clrscr();
int i,num;
printf(“ENTER THOSE NUMBER IN RANGE OF 2 AND 10= “);
scanf(“%d”,;num);
if(num==2 || num==10 || num;10 ;; num;2)
{
for(i=1;i;=5;i++)
{
printf(“%d * %d = %d
“,num,i,num*i);
}
}
else
{
printf(”
PLEASE!! ENTER THOSE NUMBERS WHICH IN RANGE OF 2 TO 10″);
}
getch();
}

When User put out of range then;

Q7. Differentiate between Backspace and Del key.

Backspace:
Backspace is a part of keyboard which is used to remove our mistakes when we write.
Del key:
Del key is also a part of keyboard which is also used to remove our mistakes but first we should those text which we want to remove. Del key also uses to delete the files, folders, images, etc.

Major Difference:
The major difference between Backspace and Del key is that when we want to remove out text that, so we use backspace and easily remove texts, but we cannot remove our data through the help of backspace key.

And Del key also removes our text but first we should select those text which we want to remove. Del key also removes the files, folders, images, etc.

Del key use purpose of backspace key but backspace key cannot use the purpose of Del key.

Q8. Why not simply put decimal integer in original string as compare to format specifier?
We cannot put decimal integer in original string because C program did not catch decimal integers, it can catch float data type means only one format specifier which is float, user can put decimal number by using float which is (%f). If user will put decimal integer so the output shows only one digit not any digits after decimal.

Q9. Differentiate between Typedef and #define.

typedef defines a type (duh!) Just as ;int; for example is a built-in type, you can define your own, either as an alias for another type, or as an aggregate of existing types in a struct, or as a list of possible values (enum).

#define is just a search-and-replace mechanism, where the thing you define is literally substituted into the source code text before it’s even parsed.

x

Hi!
I'm Mindy!

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

Check it out