Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Showing posts with label C-pointers. Show all posts
Showing posts with label C-pointers. Show all posts

Friday, May 20, 2011

C34 : Read student details from a file called stud

Back to Home   &  C


//Program to read student details from a file called stud

#include<stdio.h>
#include<conio.h>
void main()
{
int rno;
char name[20];
float mark;
FILE*file1;
clrscr();
file1=fopen("stud","r");
printf("Reading data from file...\n");
fscanf(file1,"%d%s%f",&rno,name,&mark);
printf("Printing Data...\n");
printf("Roll Number=%d\n",rno);
printf("name=%s\n",name);
printf("mark=%f\n",mark);
getch();
}
---------------------------------------------------------------
Output:

=========================================================================
Back to Home   &  C


C33 : Enter student name,roll no,and marks and store it in a file called stud

Back to Home   &  C


//Program to enter student name,roll no,and marks and store it in a file called stud


#include<stdio.h>
#include<conio.h>
void main()
{
int rno;
char name[20];
float mark;
FILE*fp;
fp=fopen("stud","w");
clrscr();
printf("Enter student roll number");
scanf("%d",&rno);
printf("Enter name");
scanf("%s",name);
printf("Enter mark");
scanf("%f",&mark);
printf("Writing to file...\n");
fprint(fp,"%d%s%f",rno,name,mark);
getch();
}
---------------------------------------------------
Output:

=========================================================================
Back to Home   &  C

Saturday, February 19, 2011

C26 : Addition of two numbers using pointer

Back to Home   &  C


//Program to print addition of two numbers by using pointer

#include<stdio.h>
#include<conio.h>
void main()
{
int num1,num2,*p1,*p2,*p3;
clrscr();
printf("Enter first number\n");
scanf("%d",&num1);
printf("Enter second number\n");
scanf("%d",&num2);
p1=&num1;
p2=&num2;
*p3=*p1+*p2;
printf("addition=%d",*p3);
getch();
}
------------------------------------------------------------
Output
Enter first number
40
Enter second number
30
Addition=70
===============================================
Back to Home   &  C

C25 : Print variable value and its address by using pointer

Back to Home   &  C


//Program to print a variable value and its address by using pointer

#include<stdio.h>
#include<conio.h>
void main()
{
int n,*pt;
clrscr();
printf("Enter a number\n");
scanf("%d",&n);
pt=&n;
printf("address of variable=%u\n",pt);
printf("Value of variable=%d",*pt);
getch();
}
----------------------------------------------------
Output
Enter a number
23
Address of variable=65524
Value of variable=23
===============================================
Back to Home   &  C

C24 : Enter a number and print it by using pointer

Back to Home   &  C


//Program to enter a number and print it by using a pointer


#include<stdio.h>
#include<conio.h>
void main()
{
int a,*p;
clrscr();
printf("Enter a number\n");
scanf("%d",&a);
p=&a;
printf("Variable Value by using pointer=%d\n",*p);
getch();
}
--------------------------------------------------
Output
Enter a number
12
Variable value by using pointer=12
===============================================
Back to Home   &  C

Friday, February 18, 2011

C23 : Print current and next memory address of a variable

Back to Home   &  C


//Print current and next memory address of a variable

#include<stdio.h>
#include<conio.h>
void main()
{
int a,*p;
clrscr();
printf("Enter a number\n");
scanf("%d",&a);
p=&a;
printf("Value in variable a=%d\n",a);
printf("Address of variable a=%u\n",p);
p=p+1;
printf("NEXT MEMORY ADDRESS OF A=%u",p);
getch();
}
-------------------------------------------------------------------
Output
Enter a number
12
Value in variable a=12
Address of variable a=65524
NEXT MEMORY ADDRESS OF A=65526
===============================================
Back to Home   &  C

Thursday, February 17, 2011

C22 : Declare a memory variable and print its address

Back to Home   &  C


//Declare a memory variable and print its address  by using a pointer variable.

#include<stdio.h>
#include<conio.h>
void main()
{
int n,*p;
clrscr();
p=&n;
printf("Address of variable n=%u",p);
getch();
}
---------------------------------------------------
Output
Address of variable n = 65524
========================================================
Back to Home   &  C