Second semester

Model Question || C Programming Solution2021|| Second Semester (BCA)
Model Question || C Programming Solution2021|| Second Semester(BCA)
2. Write a c program to generate the following output using loop.

Ans:-//a C program to generate above output using loop
#include <stdio.h>
int main(void)
{
for(int i=0; i<5; i++){
for(int j=0; j<5; j++){
if(j<i){
printf(" ");
}
else{
printf("%d",(j+1)%2);
}
}
printf("\n");
}
return 0;
}
Output:

3. How will you define pointer? Write a program that illustrate how pointer variable change the value of normal variable.
Ans:- A pointer is special type of a variable. It is special because it contains a memory address instead of values(i.e data).
Syntax:
Data_type * variable name;
Here * is called indirection operator and varilable_name is now pointer..
Example
Int *x;
Float * f;
Char *y;
// Program that illustrate how pointer variable change the value of normal variable
#include <stdio.h>
main()
{
int m=100;
int *p;
p= &m;
*p=264;
printf("\nValue of m :%d",m);
printf("\nAddress of m :%d",&m);
printf("\nAddress of m using Pointer :%d",p);
printf("\nValue of m using Pointer :%d",*p);
printf("\nAddress of Pointer :%d",&p);
}