Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Saturday, 6 April 2019

Boats and Streams

Boats and Streams

Boats and Streams Basic Concepts
• In water, the direction along the stream is called downstream.
• In water, the direction against the stream is called upstream.

Properties of Boats and stream
• You will be given the speed of the boat in still water and the speed of the stream. You have to find the time taken by boat to go upstream and downstream.
• You will be given the speed of the boat to go up and down the stream, you will be asked to find the speed of the boat in still water and speed of the stream.
• You will be given the speed of the boat in up and downstream and will be asked to
find the average speed of the boat.
• You will be given the time taken by boat to reach a place in up and downstream and will be asked to find the distance to the place.

Basic Formulas • If the speed of a boat in still water is u km/hr and the speed of the stream is v km/hr, then
• Speed of boat in downstream = ( u +v ) km/hr
• Speed of boat in upstream = (u-v)km/hr
• If the speed downstream is a km/hr and the speed upstream is b km/hr, then
• Speed in still water = [(1 / 2) * (a +b)] km/hr
• Rate of stream = (1 / 2) * (a -b) 
km/hr

Example sum
If a man can swim downstream at 8 kmph and upstream at 4 kmph, find his speed instill water?
Speed downstream a = 8 kmph
Speed upstream b = 4 kmph
Speed in still water =[( 1/ 2) * (a + b) ]kmph
= [(1/2)*(8+4)] kmph
= ( 12/2) kmph
= 6 kmph
Speed in still water = 6 kmph

Basic Formulas
• Rate of stream=[( 1/2) (a- b)] km/hr

Example sum
A man can row upstream at 6 kmph and downstream at 10 kmph, find the speed of the stream?
Speed downstream a = 10 kmph
Speed upstream b = 6 kmph
Speed of the stream =[( 1/ 2) * (a - b) ]kmph
=[(1/2*(10-6)]kmph
= (4/2) kmph
= 2 kmph
Speed of the stream = 2 kmph

General Term:
Assume that a man can row at the speed of x km/hr in still water and he rows the same distance up and down in a
stream which flows at a rate of y km/hr. Then his average speed throughout the journey
= ( Speed downstream* Speed upstream )/ Speed in still water
 = [ (x + y) * (x- y)]/ x km/hr
Let the speed of a man in still water be x km/hr and the speed of a stream be y km/hr. If he takes t hours more in upstream than to go downstream for the same distance, the distance
= [ ((x2 - Y2 )*t)/ 2y] km

A man rows a certain distance downstream in t1 hours and returns the same distance upstream in t2 hours. If the speed of the stream is y km/hr, then the speed of the man in still water

=y*[(t2 +t1 ) / (t2 –t1 ) ] km/hr

A man can row a boat in still water at x km/hr in a stream flowing at y km/hr. If it takes him t hours to row a place and come back, then the distance between the two places
= [t*( x2 - y2 ) /2x] km

A man takes n times as long to row upstream as to row downstream the river.
If the speed of the man is x km/hr and the speed of the stream is y km/hr, then x=y*[(n+1)*(n-1)]

A man can row certain distance downstream in t1 hours and returns the same distance upstream in t2 hours. If the speed of stream is y km/h, then the speed of man in still water is given 
by = y* (( t2+ t1 ) / (t2 – t1 )) km / hr
A man can row in still water at x km/h. In a stream flowing at y km/h, if it takes him t hours to row to a place and come back, then the distance between two places is given by
=t*(x2-y2)/2x

If Ratio of downstream and upstream speeds of a boat is a : b. Then ratio of time taken = b: a

Speed of stream = ((a - b) / ( a + b)) * Speed in still water.

Speed in still water = ((a + b) / (a - b)) * Speed of stream.

A man rows a certain distance downstream in x hrs and returns the same distance in y hrs. If the stream flows at the rate of z km/hr then the speed of the boat in still water is: Speed in still water
=[z*(x+y)]/(y-x)]


Average

Average

The average of a number of items of the same type is their sum divided by the number of those items.

Properties of Average;
1. If you observe the result of average closely it should be less than the greatest observation and greater than the smallest observation.
2. Suppose if the given observations are equal then the average is also the same as the observation.
3. If the zero is one of the observations of given data we have to include that zero in the calculation.
4. If all the numbers get increased by x then their average should be increased by
x. This point is also applicable for subtraction, multiplication and divide properties.

Basic Formulas
• Average = Sum of observation /Number of observation

Example sum
Ramya obtained 56, 65, 72, 86 and 92 marks ( out of 100 ) in English, maths, physics, chemistry, and biology. What are his average marks?
Average mark = Sum of mark / Number of
subject
=(56+65+72+86+91)/5
=370/5
Average mark = 74

Basic Formulas
• Average of consecutive first n natural numbers = (n +1 ) / 2
• Average of first n natural even 
numbers= (n +1 )
• Average of natural even numbers up to n = (n/ 2) +1
·  Average of first n natural odd numbers = n
• Average of natural odd numbers up
to n = (n +1
• Average of n multiples of p = (p (n +1))/2
• Average of consecutive numbers
 = (First number+ Last number) / 2
• Average of 1 to n even numbers 
= ( Last even number + 2 ) / 2
• Average of 1 to n odd numbers 
= ( Last odd number + 1 ) / 2

Example sum
Find the average of first 20 natural numbers?
Sum of first n natural number = (n * (n +1))/2
Sum of first 40 natural numbers = ( 20 * (
20+1))/ 2
=420/2
= 210
Required average = 210/ 20
= 10.5

Basic Formulas

• If a person covered a certain distance at a speed of x kmph and y kmph respectively, then his average speed will be [ ( 2xy ) / (x + y)] kmph

Example sum

A motorist travels to a place 150 km away at an average speed of 50kmph and returns at 30 kmph. His average speed for the whole journey in kmph?
Average speed = [ 2xy / ( x + y)] kmph
=[(2*50*30)/(50+30)] kmph
= ( 3000 / 80 )kmph
= 37.5 kmph


Examples For Shortcut Method
1. The average age of 10 students is 16. When the teacher joins the class then the average increases by 1. Then what is the teacher's age?
Solution : 
[Number of students * Average Age] -[Number of Students (Including Teacher) *Average Age (Including Teacher)] 
=Answer

=10*16=160

=11*17=187
Teacher’s age=187-160 =27

Shortcut Method :

Number of Students + Average Age + 1 = Answer
10+16+1=27
Teacher's age = 27 years


2. The average of 20 students is 12 years if the teacher's age is included, average increases by one. The age of the teacher is:
Solution :
[Numberof students * Average Age]-[Number of Students (Including Teacher) *Average Age (Including Teacher)]
 = Answer.
20 * 12 = 240
21*13=273
Teacher's age = 273 - 240
= 33

Shortcut Method :
Number of Students + Average Age + 1 =Answer
20+12+1 = 33
Teacher's age = 33 years
Note: This Trick works only for the problems in the above format.

Aptitude Hack#42(6-4-19)

Question:

The least perfect square, which is divisible by each of 21, 36 and 66 is:

A) 213444  

B) 214344

C) 214434


D) 231444

Age

Age

Age is to assume a fixed period with which further conditions will be compared. For example, taking 2000 as a fixed year.

Basic Formulas
If the current age is x, then n times the age is ( nx ).

Example sum
Raju's present age is 6 years. His brother age is 3 times that of Raju's age. Find his brother's age after three years?
Raju’s present age = 6 years
After three years Raju's brother age = ( 6 *
3)+3
=18+3
= 21 years

Basic Formulas
If the current age is x, then age n years later/hence= x + n.

Example sum
Rajeev age after 15 years will be 5 times his age 5 years back. What is the present age of Rajeev?
Let Rajeev present age be x years.
Rajeev age after 15 years = (x +15)
Rajeev age 5 years back = ( x- 5 )
x + 15 =5*(x-5)
x+15=5x-25
4x = 40
 x= 40 / 4
x = 10

Basic Formulas
If the current age is x, then age n years ago = x- n.

Example sum
The present age of Ram is one-sixth of his father's present age. If the difference between their present ages is 35 years,
then what is his father present age?
Let the present age of Ram be x.
Let the present age of father of Ram be y.
:.x=(1/6)y
If y -x = 35

y-(y/6)=35
(6y-y)/6 = 35

=> 5y=35*6

y=42
Father age = 42 years

Basic Formulas
The ages in a ratio a : b will be ax and bx.

Example sum
The ages of Ravi Rani are in the ratio of 3 :5. After 9 years, the ratio of their ages will become 3:4. Find the present age of Rani?
Let Ravi's age = 3x
Rani's age = 5x
(3x+9)/(5x-9)=(3/4)

4*(3x+9)=3*(5x-9)
12x+36 = 15x+27
15x -12x = 36 - 27
3x=9
x=9/3 =3
Rani's age = 5x
= 15 years

Time and Work

Time and Work

How many people can complete the task within how many days or how long it will take to complete the given work or how
much work one person can do etc.



Basic Formulas

• If a person can do a piece of work in x days, then person's one day work is (1/x)
• If a person's 1 day's work is (1 / x) then the person will complete the work in x days.
• While solving the problems assume 
the work done by person to be equal to 1. 

 Example sum
1. A alone can do a piece of work in 6 days, B alone can do the same work in 12 days. In how many days can A and B together completes the same work? 
A's 1 day work = (1 / 6)
B's 1 day's work= (1 / 12)

(A + B)'s l day's work 

= (1/6)+(1 / 12)
=(1/4)(A + B )
 will completethe work in 4 days

2. Ravi gets Rs. 110 for every day that he 
works. If he earns Rs. 2750 in a month of 31 days, for how many days did he work?Required number of days = ( 2750 / 11 )
= 25 days

Basic Formulas
• If a personA works twice as person B, then Ratio of work done by A and B is 2:1

 Example sum
A work can be finished in 16 days by twenty women. The same work can be finished in fifteen days by sixteen men.
Find the ratio between the capacity of a man and a woman?
Work done by 20 women in 1 day = 1 / 16
Work done by 1 woman in 1 day = 1 / ( 16*20)
Work done by 16 men in 1 day = 1 / 15
Work done by 1 man in 1 day = 1 / ( 15 *
16)
The ratio of the capacity of a man and woman
= (1/(15*16)):(1/(16*20))
= (1/15):(1/20)
= (1/3):(1/4)
= 4:3

Basic Formulas
If ml men can do a work in dl days and m2 men can do the same work in d2 days, then 
(m1*d1)=(m2 *d2)

Example sum
12 men can do a work in 25 days. How long will 10 men take to complete the work?
ml = 12
dl = 25
m2=10
d2 = x
( m1*d1) = (m2*d2)
( 12*25)=(10*x)
x=( 12*25)/10
= 300/10
= 30
The required number of days = 30 days

Basic Formulas
A and B working together can do a piece of work in x days whereas B working alone can do the same work in y days. How
many days will A alone take to do the 
work?

(A+B)'s one day's work = l/x
B's one day's work = l/y
A alone will complete the work in ( xy / ( y
-x)) days.

Example sum
A and B together can do a piece of work in 12 days, while B alone can finish it in 30 days. A alone can finish the work in:
A alone will complete the work in ( xy / ( y-x) )days.
x = 12
y = 30
A alone will complete the work = ( 12 * 30)/(30-12)
= (12*30)/18
=360/18
= 20
A alone will complete the work in 20 days

Time and Distance

Time and Distance
Time and distance are related to the speed of a moving object.


Properties of Time and Work
• Distance traveled is proportional to the speed of the object if the time is kept constant.
• Distance traveled is proportional to the time taken if the speed of the object is kept constant.
• Speed is inversely proportional to the time taken if the distance covered is kept constant.
• If the ratio of two speeds for the same distance is a:b then the ratio of time taken to cover the distance is b:a


Speed
Speed is defined as the distance covered by an object in unit time.

Basic Formulas

Speed = ( Distance / Time )Distance = Speed * Time
Time = ( Distance / Speed )


Example sum 
A van covers a distance of 690 km in 30h. What is the average speed of the car?
Speed = ( Distance / Time )
= 690 / 30
= 23 km/h

Relative Speed

If two objects are moving in the same direction with speeds of x and y then their relative speeds (x - y)

If two objects are moving in the opposite direction with speeds of x and y then their 

relative speed is ( x + y )


Example sum
Two trains travel in opposite directions at 36 kmph and 45 kmph and a man sitting in slower train passes the faster train in 8
seconds. Find the length of the faster train?
Relative Speed = ( 36 + 45 ) km/hr

= 81 km/hr
= 81*(5/18) m/sec
= (45/2) m/sec
Length of the train = ( 45 /2) *8 m
= 180 m

Basic Formulas

If some distance is traveled at x km/hr and the same distance is traveled at y km/hr
Average speed of the whole journey
=[(2xy ) / (x + y) ] kmph

Example sum

A person travels from A to B at a speed of 40 km/hr and returns by increasing his speed by 50%. What is his average speed
for both the trips?
Speed with which he travels from A to B =40 km/hr
Speed with which he travels from B to A =
[40*(100+50)/100]
= 60 km/hr
Average speed = (2 * 40 * 60 ) / ( 40 + 60)
= 48 km/hr

Basic Formulas

When you are given two different speeds (s1 and s2) for traveling through a certain distance, and total time (t) for these two
journeys:
Distance = [ (s1*s2) / (sl +s2 ) ]*t


Example sum

A boy goes from A to B at 3 km/hr,back from B to A at 2 km/hr.Total time for these two journeys is 5 hours, then
distance from A to B is given by:
Distance = ( Product of speeds / Addition of speeds ) * Time
Distance= [(3*2)/(3+2)]*5
= [ 6/5]*5
= 6 km

Basic Formulas

When you are given two different speed  (s1 and s2) for  travelling through a certain distance, and total difference in time (t) is
given for these two journeys: Distance = [ (s1*s2)/(s2 - sl ) ] *t  

Example sum

A boy goes from A to B. If speed is 30km/hr ,he is late by 10 minutes. If speed is 40 km/hr,he reaches 5 minutes earlier, then distance from A to B is given by?
Difference in time = 10 - (-5) [ earlier 5 min = (-5) ]
= 15 minutes
= (15/60) hr
= 1/4 hr
Distance = ( Product of speed / Difference of speed ) * Difference in time
= [(30 * 40)/(40-30)]*(1/4)
= (1200/10)*(1/4)
= 120*(1/4)
= 30 km  

Friday, 5 April 2019

Aptitude Hack#41(5-4-19)

Question:

Two ships are sailing in the sea on the two sides of a lighthouse. The angle of elevation of the top of the lighthouse is observed from the ships are 30° and 45° respectively. If the lighthouse is 100 m high, the distance between the two ships is:

A) 173 m
B) 200 m
C) 273 m
D) 300 m


Profit and Loss

Profit and Loss


Cost price

Cost price is defined as price at which an article is purchased.

Selling price

Selling price is defined as price at which an article is sold.

Profit

If Selling Price is more than Cost Price, then there is profit SP > CP, (Selling price is greater than Cost Price)
Profit = ( SP - CP )

Loss

If Selling Price is less than CP then there has been a loss occurred. SP < CP, (Selling price is less than Cost Price)
Loss = (CP - SP )

Basic Formulas

1. Profit = ( SP - CP )
2. SP = ( profit + CP )
3. CP = (SP - profit)
4. Profit % = ( profit * 100 ) / CP
5. SP = CP*[1+(profit%/ 100)]
6. CP = ( 100*SP ) / ( 100 * profit%)
7. Loss = ( CP - SP )
8.SP =(CP - loss)
9. CP=(SP+ loss)
10. Loss % = ( loss * 100 ) / CP

Example sum

1. Arjun buys an mobile cover for Rs. 100 and sells it for Rs. 110. Find him profit?
Cost price = Rs. 100
Selling price = Rs. 110
Profit = Selling Price - Cost Price
= (110-100)
= Rs. 10

2. Arjun buys an mobile cover for Rs. 100 and sells it for Rs. 80. Find his Loss?
Cost price = Rs. 100
Selling price = Rs. 80
Loss = Cost Price - Selling Price
= Rs. (100 - 80)
= Rs. 20

3. Arjun buys an mobile cover for Rs. 100 and sells it for Rs. 110. Find him profit percent?
Cost price = Rs. 100
Selling price = Rs. 110
Profit = Selling Price - Cost Price
= Rs. (110- 100)
= Rs. 10
Profit % = [(10/ 100) * 100]
=10%
4. Arjun buys an mobile cover for Rs. 100and sells it for Rs. 80. Find his Loss percent?
Cost price = Rs. 100
Selling price = Rs. 80
Loss = Cost Price - Selling Price
= Rs. (100 - 80)
= Rs. 20
Loss % = [ (20 /100 ) * 100]%
= 20%

5. Selling price of an article is Rs. 2220 and the percent profit earned is 20%. What is the cost price of the article?
Selling Price ( SP ) = 2220
Profit percentage = 20%
Cost Price ( CP) = [ 100 / ( 100 +Gain %)] * Selling price
=[100/(120)]* 2220
= 370 * 5
=Rs. 1850

General Terms:

  • If two articles are sold first article at x% profit and the second article at y% loss, thus making no profit, no loss in the transaction, Then cost price of the two articles are in the ratio y : x
Proof:
Profit on the first article = ax / 100
Loss on the second article = by / 100
There is no profit or no loss in the bargain. =
ax/ 100 = by / 100
ax = by
a/b=y/x


Example sum:A man purchased two articles for total cost of Rs. 9000. He sold the first article at 15% profit and the second at 12% loss. In the bargain, he neither gained nor lost anything. Find cost price of the first article.

Ratio of cost price of the first and the second article = 12 : 15
= 4:5
Cost price of the first article
= (4/ 9) *9000= 4*1000
= Rs.4000
















  • If two article are sold at equal prices,the first one is sold at P1% Profit and whereas the second one at a Profit of P2% And the sum of the cost price of twoarticle is x, then
  • Cost price of an article at profit P1% = [ (100+P2/(200+P1+P2)]*x


Example sum:A trader bought two watches for Rs 2300. He sold one at a profit of 10% and the other at a profit of 20%. If the selling price of each watch is the same, then their cost
price are respectively.
Cost price of an article at profit P1% = [ (100+P2/(200+P1+P2)]*x
P1=10%
P2=20%
x = Rs. 2300
Cost price of a watch at profit of 10%=[(100+20)/(200+10+20)]* 2300
= 120*10
= Rs. 1200
Cost price of a watch at profit of 20% = 2300 - 1200
= Rs. 1100


Ratio and Proportion

Ratio and Proportion


The ratio is a quantity which represents the relationship between two similar quantities.

If the two quantities are a and b, the ratio of a and b represented as a: b or ( a/ b ) Here a is called antecedent and b is called Consequent

Basic Formulas


The ratio of two quantities a and b in the same units is the fraction and we write it as a: b.

Example sum

Divide Rs. 672 in the ratio 5 : 3
Sum of ratio terms = ( 5 +3 )
= 8
First part= Rs. ( 672*(5/8))
= Rs. 420 Second part= Rs. (672 * (3/8))
=Rs. 252

          Types of Ratio









Fourth Proportional

If a : b = c : d, then d is called the fourth proportional to a, b, c.
Example sum

Find the fourth proportion to 2,3,6?
Let the forth proportional 2, 3 and 6 be x.
=>2:3::6:x
=>(2/3)=(6/x)
=> x=18/2 = 9

Third Proportional


a : b = c : d, then c is called the third proportion to a and b.
Example sum
Find the third proportion to 16 and 36?
Let the third proportional 16 and 36 be x.
16: 36 :: 36:x
16*x=36*36
x=(36*36)/16 =81

Comparison of Ratios

We say that (a:b)<(c:d)=>(a/b)>(c/d)
Example sum
1. Find the ratio between 20 and 32?
Ratio = 20 / 32
=5/8



2. Two numbers are in the ratio 3: 5. If 9 is subtracted from each, the new numbers are in the ratio 12: 23. Find a smaller number?
Let the numbers be 3x and 5x.
=> (3x-9)/(5x-9)=(12/23)
23*(3x-9) = 12*(5x-9)
69x – 207=60x – 108
69x – 60x = 207 – 108
9x = 99
x = 11
The smaller number = 3 * 11
= 33

Thursday, 4 April 2019

Sixth Week Term Work Program 2 (Hashing)

Question:
Post Graduate course of CSE department can accommodate a maximum of 20 students. Each
PG student in the department is identified by his/her Roll No, USN, Name, Semester and
Mobile Number. Using the appropriate Collection class, write a Java Program to simulate the
following scenarios:
a. On request, the capacity got increased from 20 to 25.
b. Only 10 students enroll for the course.
c. Four students from Roll No.s 3 – 6 voluntarily un-enroll from the course.
d. After a month, six more students get enrolled in the course.

e. Print the information of all the students currently enrolled in the course.

Java Program:

import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.List;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Map;


class StudentDetails{
String name;
String usn;
String div;
String Course="Java";
int sem;
StudentDetails(String name, String usn, String div,  int sem){
this.name=name;
this.usn=usn;
this.div=div;
this.sem=sem;
}

}

public class PgStudent {
public static void main(String[] args) {



Map<Integer,StudentDetails> map=new HashMap<Integer,StudentDetails>(); 
//Creating students
StudentDetails s1=new StudentDetails ("amar","2sd15cs08","b",4); 
StudentDetails  s2=new StudentDetails("Akbar","2sd16cs10","b",4); 
StudentDetails s3=new StudentDetails("Antony","2sd16cs09","b",4); 
StudentDetails s4=new StudentDetails("Ajay","2sd16cs01","b",4);
StudentDetails s5=new StudentDetails("siya","2sd16cs02","b",4);
StudentDetails s6=new StudentDetails("Riya","2sd16cs03","b",4);
StudentDetails s7=new StudentDetails("Maya","2sd16cs04","b",4);
StudentDetails s8=new StudentDetails("Shriya","2sd16cs05","b",4);
StudentDetails s9=new StudentDetails("Fida","2sd16cs06","b",4);
StudentDetails s10=new StudentDetails("Jiya","2sd16cs07","b",4);
//Adding Students to map 
map.put(1,s1);
map.put(2,s2);
map.put(3,s3);
map.put(4,s4);
map.put(5,s5);
map.put(6,s6);
map.put(7,s7);
map.put(8,s8);
map.put(9,s9);
map.put(10,s10);


//Traversing map
for(Map.Entry<Integer, StudentDetails> entry:map.entrySet()){ 
int key=entry.getKey();
StudentDetails b=entry.getValue();
System.out.println("Student "+key);
System.out.println(b.name+" "+b.usn+" "+b.div+" "+b.sem+" "+b.Course); 

System.out.println("-----------------------------------------------------------");



System.out.println("Now students having Usn 3 to 6  will unroll from the course");
map.remove(3);
System.out.println("Student having roll no 3 unrolled");
map.remove(4);
System.out.println("Student having roll no 4 unrolled");
map.remove(5);
System.out.println("Student having roll no 5 unrolled");
map.remove(6);
System.out.println("Student having roll no 6 unrolled");
System.out.println("-----------------------------------------------------------");
System.out.println("List of students after un-rolling from course");
System.out.println("-----------------------------------------------------------");
for(Map.Entry<Integer, StudentDetails> entry:map.entrySet()){ 
int key=entry.getKey();
StudentDetails b=entry.getValue();
System.out.println("Student "+key);
System.out.println(b.name+" "+b.usn+" "+b.div+" "+b.sem+" "+b.Course); 

System.out.println("-----------------------------------------------------------"); 

//After a month 6 more students enrolled

StudentDetails s11=new StudentDetails ("ADI","2sd15cs11","b",4); 
StudentDetails  s12=new StudentDetails("JAI","2sd16cs12","b",4); 
StudentDetails s13=new StudentDetails("RUHI","2sd16cs13","b",4); 
StudentDetails s14=new StudentDetails("RIMA","2sd16cs14","b",4);
StudentDetails s15=new StudentDetails("AMY","2sd16cs15","b",4);
StudentDetails s16=new StudentDetails("ARYA","2sd16cs16","b",4);

map.put(3,s11);
map.put(4,s12);
map.put(5,s13);
map.put(6,s14);
map.put(11,s15);
map.put(12,s16);
System.out.println("Currently Updated list");
for(Map.Entry<Integer, StudentDetails> entry:map.entrySet()){ 
int key=entry.getKey();
StudentDetails b=entry.getValue();
System.out.println("Student "+key);
System.out.println(b.name+" "+b.usn+" "+b.div+" "+b.sem+" "+b.Course); 

System.out.println("-----------------------------------------------------------");
}


}

Credits: Sonali 

ftell

FTELL Function


The ftell() function shall obtain the current value of the file-position indicator for the stream pointed to by stream.


Syntax

The syntax for the ftell function in the C Language is:
long int ftell(FILE *stream);

Parameters or Arguments

stream
The stream whose file position indicator is to be returned.

Returns

The ftell function returns the current file position indicator for stream. If an error occurs, the ftell function will return -1L and update errno.

Required Header

In the C Language, the required header for the ftell function is:
#include <stdio.h>


C program:

#include <stdio.h>

int main(void)
{
    FILE *stream;
    stream = fopen("MYFILE.TXT", "w+");
    fprintf(stream, "This is a test");
    printf("The file pointer is at byte %ld\n", ftell(stream));
    fclose(stream);
    return 0;
}

Output:
The file pointer is at byte 14