Friday, 12 February 2016

Aptitude Question Numbers Basics

Aptitude Questions (Numbers Basics)                

 Numbers Basics

Number system is a very important chapter and you will get questions from this area in many competitive exams.  We start with classification of numbers.

Types of numbers :
1. Natural numbers (N) = 1, 2, 3, . . . .
2. Whole numbers (W) = 0, 1, 2, 3, . . . .
3. Intezers (Z) = −∞ . . . −2, −1, 0, 1, 2, 3, . . .
4. Rational numbers (Q) = The numbers of the form pq  where q ≠ 0.  Eg: 15 , 0.46, 0.333333
5. Irrational numbers (I) = The numbers of the form x1n  ≠ Intezer.  Also π and e also irrational numbers.

Other types of numbers:
a. Even numbers : Numbers which are exactly divisible by 2.  These numbers are in the format of 2n.
b. Odd numbers: Numbers which gives remainder 1 when divided by 2. These numbers are in the format of 2n ± 1.
c. Prime numbers : The numbers which are divisible by 1 and the number itself are primes.  The least prime is 2.
d. Composite numbers : The numbers of which are divisible by more than 2 numbers.

The following rules related to Even and Odd numbers are important:
odd ± odd = even;
even ± even = even;
even ± odd = odd

odd × odd = odd;
even × even = even;
even × odd = even.

odd(any number) = odd
even(any number) = even

Fundamental Theorem of Arithmetic: Any intezer greater than 1 is either prime or product of primes. Writing a number as a product of primes is called prime factorization. For example, 100 can be written as 22 × 5

Solved Examples

1. 45 of a number exceeds its 23 by 8. The number is 
a. 30
b. 60
c. 90
d. None of these
Correct Option : B
Explanation:
Let the number be 'a'.
45a23a=8
12a10a15=8
2a=120a=60

2. If 1 is added to the denominator of fraction, the fraction becomes 12.  If 1 is added to the numerator, the fraction becomes 1.  The fraction is 
a. 47
b. 59
c. 23
d. 1011
Correct Option: C
Explanation:
Let the required fraction be ab. Then
ab+1=122ab=1 ---- (1)
a+1b=1  ab=1 ------- (2)
Solving (1) & (2) we get a = 2, b=3
Fraction = ab=23

3. The sum of two numbers is twice their difference.  If one of the numbers is 10, the other number is
a. 313
b. 30
c. 313
d. a or b
Correct Option:  D
Explanation:
Let the other number be a. 
Given that, 10+a=2(a10)a=30
or if the other number is less than 10, 10+a=2(10a)a=103=313

4. The sum of squares of two numbers is 80 and the square of their difference is 36.  The product of the two numbers is.
a. 22
b. 44
c. 58
d. 116
Correct Option: A
Explanation :
Let the numbers be x and y . Then
x2+y2=80 and (xy)2=36
(xy)2=36x2+y22xy=36
2xy=(x2+y2)36=8036=44
xy=22

5. 11 times a number gives 132.  The number is 
a. 11
b. 12
c. 13.2
d. None
Correct Option: B
Explanation:
Let the number be 'N'
11×N=132N=12

6. If 1/5th of a number decreased by 5 is 5, then the number is 
a. 25
b. 50
c. 60
d. 75
Correct Option: B
Explanation :
Let the number be a, then
a55=5a5=10a=50

7. The difference of two numbers is 2 and the difference of their squares is 12.  The sum of the number is 
a. 6
b. 8
c. 10
d. 22
Correct Option: A
Explanation:
Let the numbers be a, b;  a-b=2 and
a2b2=12
a+b=a2b2ab=122=6

8. The sum of two numbers is 29 and the difference of their squares is 145.  The difference between the number is
a. 13
b. 5
c. 8
d. 11
Correct Option: B
Explanation:
Let the numbers be x and y, then
(xy)=x2y2(x+y)
=14529=5

9. The difference between the squares of two consecutive numbers is 35.  The numbers are
a. 14,15
b. 15,16
c. 17,18
d. 18,19
Correct Option: C
Explanation:
Let the numbers be a and (a+1)
(a+1)2a2=35
a2+2a+1a2=35
2a=34 or a = 17
The numbers are 17 & 18.

10.3th4of1th5 of a number is 60.  The number is 
a. 300
b. 400
c. 450
d. 1200
Correct Option: B
Explanation:
Let the number be N. Then
34×15×N=603N=1200N=400

11. 24 is divided into two parts such that 7 times the first part added to 5 times the second part gives 146. The first part is 
a. 11
b. 13
c. 16
d. 17
Correct Option: B
Explanation:
Let the first and second parts be a and 24  a, then
7a+5(24a)=146
7a+1205a=146
2a=26 or a = 13

12. The product of two numbers is 120.  The sum of their squares is 289.  The sum of the two numbers is :
a. 20
b. 23
c. 169
d. None
Correct Option: B
Explanation:
Let the number be x and y . Then
(x+y)2=(x2+y2)+2xy=289+2x120
=289+240=529x+y=529=23

13. The sum of squares of two numbers is 68 and the square of their difference is 36.  The product of the two numbers is 
a. 16
b. 32
c. 58
d. 104
Correct Option:a
Explanation:
Let the numbers be x and y. Then
x2+y2=68&(xy)2=36
But (xy)2=36x2+y22xy=36
682xy=362xy=32
xy=16

14. The sum of seven numbers is 235.  The average of the first three is 23 and that of the last three is 42.  The fourth number is 
a. 40
b. 126
c. 69
d. 195
Correct Option: A
Explanation:
(23×3+a+42×3)=235a=40

15. Two numbers are such that the ratio between them is 3:5 but if each is increased by 10, the ratio between them becomes 5 : 7, the numbers are
a. 3, 5
b. 7, 9
c. 13, 22
d. 15, 25
Correct Option: D
Explanation:
Let the numbers be 3a and 5a
Then 3a+105a+10=57
7(3a+10)=5(5a+10)a=5
The numbers are 15 & 25

16.  A fraction becomes 4 when 1 is added to both the numerator and denominator, and it becomes 7 when 1 is subtracted from both the numerator and denominator.  The numerator of the given fraction is :
a. 2
b. 3
c. 7
d. 15
Correct Option: D
Explanation:
Let the required fraction be ab
Then a+1b+1=4a4b=3
and a1b1=7a7b=6
Solving these equations we get,
a=15
b=3

17. A number exceeds 20% of itself by 40.  The number is
a. 50
b. 60
c. 80
d. 320
Correct Option: A
Explanation:
Let the answer be 'a'
Then a20100a=405aa=200
a=50

18. Three numbers are in the ratio 3:4:5.  The sum of the largest and the smallest equals the sum of the third and 52.The smallest number is :
a. 20
b. 27
c. 39
d. 52
Correct Option: C
Explanation:
Let the numbers be 3 N, 4 N and 5 N
Then 5N+3N = 4 N +52
4N=52N=13
The smallest number =3N=3 x 13=39

19. If 16% of 40% of a number is 8, then the number is 
a. 200
b. 225
c. 125
d. 320
Correct Option: C
Explanation:
Let 16100×40100×a=8

a = 8×100×10016×40=125

20. If 3 is added to the denominator of a fraction, it becomes 13 and if 4 be added to its numerator, it becomes 34 ; the fraction is :
a. 49
b. 320
c. 724
d. 512
Correct Option: D
Explanation:
Let the required fraction be ab
Then ab+3=13
3ab=3 and
a+4b=344a3b=16 solving,we get
a=5, b=12; required answer = 5/12

21.Of the three numbers, the first is twice the second and is half of the third.  If the average of three numbers is 56, then the smallest number is
a. 24
b. 36
c. 40
d. 48
Correct Option: A
Explanation:
Let the second number is a. Then the first number is 2a and third number is 4a.
2a+a+4a3=567a=3×56 or
a= 3×567=24
Smallest number is 24

22.The difference of two numbers is 8 and 1th12 of the sum is 1.  The numbers are
a. 10, 2
b. 18, 26
c. 10, 18
d. 26, 34
Correct Option: A
Explanation :
Let the numbers be a and (a+8). Then
112[a+(a+8)]=12a+8=12
a=2,a+8=10

23.A number is 25 more than its 25th. The number is 
a. 60
b. 80
c. 1253
d. 1257
Correct Option: C
Explanation:
Let the number be N. Then
N25=25Nor5N125=2N
or N=125/3

24.The sum of three numbers is 68.  If the ratio between first and second be 2 : 3 and that between second and third be 5 : 3, then the second number is 
a. 30
b. 20
c. 58
d. 48
Correct Option: A
Explanation:
Let the numbers be x,y,z.  Then
xy=23,yz=53xy=2×53×5=1015
and yz=5×33×3=159
x:y:z=10:15:9

25. The sum of two numbers is 100 and their difference is 37. The difference of their squares is
a. 37
b. 100
c. 63
d. 3700
Correct Option: D
Explanation:
Let the numbers be x and y
Then x+y=100 & x-y=37
x2y2=(xy)(x+y)=100×37=3700

26. What least number must be subtracted from 12702 to get number exactly 99 ?
a. 49
b. 30
c. 29
d. 31
Correct Option: B
Explanation:
99)  12702 (128
       99 
     280
     198
     822
     792
      30

Required number is 30.

27. The largest number of four digits exactly divisible by 77 is 
a. 9768
b. 9933
c. 9988
d. 9944
Correct Option: B
Explanation:  Find the remainder when 10000 is divided by 77.  Then substract that remainder from 10000. you can solve this by taking 9999 also.

28. Sum of the numbers from 1 to 20 is 
a. 210
b. 110
c. 220
d. 105
Correct Option: A
Explanation: Sum of first n natural numbers = 1 + 2 + 3 + ..... n = n(n+1)2
Substitute n = 20.

29. Sum of even numbers between 15 and 25 is
a. 70
b. 80
c. 130
d. 100
Correct Option: D
Explanation: 16 + 18 + .......24.
Taking 2 common we get = 2 ( 8 + 9 + 10 +.....+ 12)
Sum of n natural numbers upto 12
8 + 9 + 10 +.....+ 12 = (1 + 2 + 3 + ......+  12) - ( 1 + 2 + 3 + ....+ 7)
By applying the formula for the first n natural numbers sum n(n+1)2 we get, 12(12+1)27(7+1)2=50
So 16 + 18 + .......24 = 2 x 50 = 100

30. How many numbers between 1000 and 5000 are exactly divisible by 225?
a. 16
b. 18
c. 19
d. 12
Correct Option: B
Explanation: First multiple of 225 after 1000 is 1125 (225 x 5 ) and last multiple of 225 before 5000 is 4950 (225 x 22)
Total number are lad+1=49501125225+1=18

31. If the first 200 numbers are written down and those divisible by 2 are deleted and again those divisible by 5 are deleted, how many numbers are left out ?
a. 80
b. 150
c. 200
d. 160
Correct Option: A
Total numbers divisible by 2 = 100
Total numbers divisible by 5 = 40
But there is double counting. So we have to substract Total numbers which are divisible by both 2 and 5 i.e, 200 / 10 = 20
So Total numbers which are divisible by either 2 or 5 is 100 + 40 - 20 = 120
Number of numbers which are not divisible by any of those = 200 - 120 = 80

32. How many digits are required to write numbers between 1 to 100.
a. 196
b. 158
c. 192
d. 200
Correct Option: C
Explanation:
Single digits are from 1 to 9 = 9 digits
Doubt digits are from 10 to 99 = 90 x 2 = 180 digits
100 needs 3 digits.  Total 192 digits

33. When simplified, the product :
 [213][235][257]. . . [2997999]
a. 5999

b. 1001999

c. 10013

d. None of these
Correct Option: C
Explanation:
[213][235][257]....[2997999] = 53×75×97×....×1001999
10013

34. If 2x1+2x+1=320, then the value of x is :
a. 4
b. 5
c. 6
d. 7
Correct Option: D
Explanation:
Try to plugin options.  For x = 7 we get 320.

35. Which one of the following numbers is not a square of any natural number ?
a. 17956
b. 18225
c. 53361
d. 63592
Correct Option: D
Explanation: Square of any number ends with 0, 1, 4, 5, 6, 9 only

Wednesday, 10 February 2016

C Basics Interview questions and answer of C with explanation for fresher

                                          C Basics

      Interview questions and answer of C with explanation for fresher

What is C language?

The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system.  C is the most popular programming language used for writing system software as well as for business packages.

What are the features of C?

1.C is a procedural-Oriented programming language .
2.C is a compiler-based language.
3.C is a middle-level language.
4.C uses the top-down approach
5.Programs written in C are efficient and fast.
6.C is highly portable language.


Terminology:-


  • Character Set: A character denotes any alphabet, digit, white space or any special symbol that is used to represent information. A character set is collection of characters.
  • Token: A token is the smallest individual unit of a program.
  • Instruction: An instruction is a statement that is given to computer to perform a specific operation.
  • Function: A function is a collection of instructions that performs a particular task.
  • Program: A program is a well-organized collection of instructions that is used to communicate with the computer system to accomplish desired objective.


How many files are created when a C program is written using Borland c compiler?
When a C program is written, four files will be created:
  1. Source file (e.g., first.c)
  2. Back up file (e.g, first.bak)
  3. Object file (e.g., first.obj)
  4. Executable file (e.g., first.exe)
What are the steps in executing a C program?

Language processors are the system softwares that play key role in translating a source file into an executable file. These language processors include: preprocessor, compiler, linker and loader. The translation process from source file into an executable file is depicted as follows:
  1. Entering a Program:- A text editor is used for this task. The statements written by the programmer are called source code and the file in which the statements are saved is called as source file.
  2. Preprocessing:- During the first phase of this process, a program called the preprocessor reads the source code. The preprocessor searches for special lines that begin with the # symbol. These lines (usually, called as preprocessor directives) contain commands that cause the preprocessor to modify the source code in someway. The preprocessor modifies the existing source code and stores modified source code into another file.
  3. Compiling:- During the next phase, the compiler steps through the preprocessed source code, translating each modified source code instruction into the appropriate machine language instruction. This process will uncover any syntax error that may be in program. If the program is free of syntax errors, the compiler stores the translated machine language instructions, which are called object code, in an ‘object’ file.
  4. Linking:- During the last phase of the translation process, another program called the linker combines the object file with library routines. Once the linker is finished with this step, an executable file is created. The executable file contains machine language instructions, or executable code, and is ready to run on the computer.
  5. Loading:- Once, the executable file is stored on disk, the loader that is a part of operating system brings it to main memory and starts it running.
This translation process is shown in the following figure:


What are the differences between break and exit() statements?

Break
exit()
1) It is used to come out of loop or switch or block in which it is placed.
1) It is used to come out of entire program.
2) It is a keyword. Its definition has already defined by language developers.
2) It is a pre-defined function that is available inprocess.h or stdlib.h header files. It takes an argument: 0 or 1. exit(0) means a clean exit without an error message. exit(1) means an abrupt exit with an error message.


When does the goto statement is used compulsary? Why should we avoid the use of goto statement?
goto statement is the best option when one wants the control jumps from inner most loop to outer most loop at once.  
goto statement causes the loss of sequentiality in order of execution of instructions. Often, this leads us to difficulty in understanding the program. Hence, it is suggested that one should avoid the use of goto statement.

Type Qualifiers:-

Type qualifiers are the keywords that add new meanings to existing data types. There are two type qualifiers:constvolatile. 


  • Making a variable as read-only variable: In order to make the value of variable as unchanged during the execution of a program, initialize the variable with the type qualifier const as follows:


Ex: const double PI=3.1412;

This initialization tells the compiler that the value of PI must not be modified by the program. However, it can be used on the right hand side of assignment statement like other variable.
Ex: double x;
     x=PI;  

  • Making a variable as modifiable externally: In order to make variable’s value modifiable at any time by some external sources (from outside program), we use type qualifier volatile. For example,
          volatile int  x;

The value of x may be altered by some external factors even if it does not appear on the left-hand side of an assignment statement. When we declare a variable as volatile, the compiler will examine the value of the variable each time it is encountered to see whether any external alteration has changed the value.  


Some Interview Questions:


1. What is Scope?
Scope refers to the visibility of a function or variable.
If the function or variable is visible outside of the current source file, it is said to have global, or external, scope.
If the function or variable is not visible outside of the current source file, it is said to have local, or static, scope.

2. What is modular programming?
If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.

3. Is using exit() the same as using return?
No. The exit() function is used to exit your program and return control to the operating system. The return statement is used to return from a function and return control to the calling function. If you issue a return from the main() function, you are essentially returning control to the calling function, which is the operating system. In this case, the return
statement and exit() function are similar.

4. What is dangling else problem?
Dangling else problem is an ambiguous situation in which one can not judge the else statement to which if statement it belongs to. E.g., in the above syntax, we can not judge the else statement whether it belongs to outer if statement or inner if statement.
In order to solve this problem, it is better to include the outer-if-body in curly braces. Hence, the above syntax can be redefined as:




5. What is a modulus operator? What are the restrictions of a modulus operator?
A Modulus operator gives the remainder value. The result of x%y is obtained by (x-(x/y)*y). This operator is applied only to integral operands and cannot be applied to float or double.

6. Differentiate between a linker and linkage?
A linker converts an object code into an executable code by linking together the necessary build in functions. The form and place of declaration where the variable is declared in a program determine the linkage of variable.

7. What is an argument? Differentiate between formal arguments and actual arguments?
An argument is an entity used to pass the data from calling function to the called function. Formal arguments are the arguments available in the function definition. They are preceded by their own data types. 
Actual arguments are available in the function call.

8. Can a variable be both const and volatile?
Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. Const is the qualifier that provides more data security by throwing error when an accidental attempt is made to modify the same.However, the value can be changed by hardware on the computer, so it was declared volatile. If a variable is both const and volatile, the two modifiers can appear in either order.

9. What are the different storage classes in C? 
There are 4 storage classes in C.
1.Auto
2. static
3.extern
4. register

Static-duration variables are allocated in main memory, usually along with the executable code of the program, and persist for the lifetime of the program. Global variables (i.e, file scope) with or without the static specifier also have static scope.
Automatic-duration variables are allocated on the stack and come and go as functions are called and return. Variable having block scope and without static specifier have automatic storage duration.

Dynamic memory allocation in which memory is more explicitly (but more flexibly) managed, typically, by allocating it from the heap, an area of memory structured for this purpose.
Register variables uses processor registers to store their contents if available. If not  they will be converted to auto variables automatically.

10. What does static variable mean?
There are 3 main uses for the static.
1. If you declare within a function,it retains the value between function calls
2.If it is declared for a function name, it is invisible for the outer files.
(By default function is extern..so it will be visible from other files )
3. Static for global variables: that variable is limited to with in the file.
(By default we can use the global variables from outside files)


11. What are the differences between malloc() and calloc()?
There are 2 differences.
First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable).
Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

12. What is the difference between declaring a variable and defining a variable?
Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also initialize a variable at the time it is defined.

13. What is an lvalue?
An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement,whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant.

14. Differentiate between an internal static and external static variable?
An internal static variable is declared inside a block with static storage class whereas an external static variable is declared outside all the blocks in a file.An internal static variable has persistent storage,block scope and no linkage.An external static variable has permanent storage,file scope and internal linkage.

15. When is a switch statement better than multiple if statements?
A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type.

16. What is a static function?
A static function is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable. If the function or variable is visible outside of the current source file, it is said to have global, or external, scope. If the function or variable is not visible outside of the current source file, it is said to have local, or static, scope.

17. What is a modulus operator? What are the restrictions of a modulus operator?
A Modulus operator gives the remainder value. The result of x%y is obtained by (x-(x/y)*y). This operator is applied only to integral operands and cannot be applied to float or double.

18. Why should I prototype a function?
A function prototype tells the compiler what kind of arguments a function is looking to receive and what kind of return value a function is going to give back. This approach helps the compiler ensure that calls to a function are made correctly and that no erroneous type conversions are taking place.

Tuesday, 9 February 2016

C++ Placement Questions and Answers

C++ Placement Questions and Answers
1.A property which is not true for a classes
a).are removed from memory when not in use
b).permit data to be hidden from other classes.
c).bring together all aspects of an entity in one place.
d).Can closely model objects in the real world.

2.Which of the following cannot be legitimately passed to a function in c++.
a)constant           b)variable           c)structure             d)header file.

3.this pointer is
a)implicitly points to an object                                   b)can be explicitly used in a class.
c)can be used to return an object                               d)All of the above.
e)All of the above

3.To perform I/O stream with disk files in C++, you should
a)open and close files as in procedural languages.
b)use classes derived from ios.
c)use C language library functions to read and write data.
d)include the IOSTREAM.H header file.

4.RunTime Polymorphism is achieved in C++ by using______
a)friend function   b)virtual function   c)operator overloading   d)function overloading

5.In C++ dynamic binding the code matching the object under current reference will be called at.
a)Compile time          b)Run time           c)Editing time            d)Binding time

6.Following are the object oriented programming language
a)JAVA               b)C++                c)Small talk               d)All of above

7.How many characters are recognized by ANSI C++?
a)32           b)64               c)no limit               d).none of these

8.Inheritance is the process of
a).Object of one class acquires the properties of objects of another class
b).Variable of one class acquires the properties of variable of another class
c).Object of one class acquires the properties of objects of same class
d).Variable of one class acquires the properties of objects of another class

9.By default Class members are
a)Public                b)Private              c)Protected               d)nherited

10.How many words can be read by cin?
a)one                   b)Two              c)Three                d)Four

C++   Placement Questions and Answers

11.A function that is called automatically when an object is created is called as
a)constant               b)constructor             c)static            d)friend

12.The null character will take space of
a)0 byte                  b)2 byte               c)1 byte                d)8 byte

13.This operator is used to allocate memory dynamically
a)new                b)delete             c)static                  d)real

14.Which one is correct to declare an interface in a class?
a).By making all the methods pure virtual in a class
b).By making all the methods abstract using the keyword abstract in a class
c).By declaring the class as interface with the keyword interface
d).It is not possible to create interface class in C++

15.Keywords support dynamic method of resolution is
a)abstract                   b).Virtual               c)Dynamic              d)Typeid

16.Which pointer is implicit pointer passed as the first argument for non-static member functionsin C++?
a)self pointer          b)std::auto_ptr pointer                  c).Myself pointer              d)this pointer

17.Inventor of C++ language is
a)John Dell                 b)Bjarne Stroustrup                 c)Thomusn Steve             d)Karl Thomus

18.Destructor can have following number of argument
a)2            b)1                 c)0                 d)any no of arguments

19.How does code-bloating occur in C++?
ANSWER:-        Improper use of Inline functions and templates may lead to code bloating. Multiple Inheritance may also lead to code bloating


20.Explain  about a.) Function overloading b.) Operator overloading
Function overloading:
The capability of C++ to define several functions of the same name with different sets of parameters is called function overloading. While calling an overloaded function, the C++ compiler selects the proper function by examining the number, types and order of the arguments.
Function overloading is commonly used to create several functions of the same name that perform similar tasks but on different data types.
Operator overloading:
When the existing C++ operators are redefined to work on objects of user-defined classes, it is called operator overloading.
Overloaded operators form a pleasant facade which improve the understandability and reduce maintenance costs without adding anything fundamental to the language.

Sunday, 7 February 2016

Introduction To Single Linked List

Introduction To Single Linked List

Description 

  • In a single-linked list every element contains some data and a link to the next element(link), which allows to keep the structure.
  • In this type of Linked List two successive nodes are linked together in linear fashion.
  • Each element of the list is called a “node”.
  • First node is called “head” and it’s a dedicated node. By knowing it, we can access every other node in the list. 
  • Last node of the list is called “Tail”,By knowing it we can perform add operation.
  • Each Node contain address of the next node to be followed.
  • In Single Linked List only Linear or Forward Sequential  movement(traversal) is possible.
  • Elements are accessed sequentially, no direct access is allowed.

Structure of single linked list

  • Every node of a singly-linked list contains following information
    • A value (primitive data/user define data).
    • A link to the next element (pointer data).
  • Sketchy, it can be shown like this…
slink structure
Example 1:   primitive data type single lined list
                             struct single_link_list
                               {
                                        int data;
                                        struct slink*next;
                                };
Example 2:   User define data type single lined list
                              struct emp
                                {
                                         int id;
                                         char name[36];
                                          int sal;
                                 };
                                 struct single_link_list
                                 {
                                       struct emp data;
                                       struct slink*next;
                                   };

Single linked list Internal representation

  • In Singly-linked list implementation First node called head and no other node points to it.
  • Link to the head is usually stored its data and information of next data structure(Next link). For empty list, head initial value is set to “NULL”.
  • in Single linked list Last node called “Tail” usually stored its data and Next link data value is set to “NULL” because it is terminal node.
  • Below you can see another picture, which shows the whole singly-linked list internal representation..
single linked list structure_image2

 Operations on Single Linked List

  • Adding node
  • Inserting  node
  • node Count
  • Traversal
  • Deletion node
  • Updating node data