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

Sunday, 24 January 2016

Sanam Re full HD Video Songs Download



 SANAM RE - TRAILER



 SANAM RE TITLE SONG





 GAZAB KA HAI YEH DIN




 HUA HAIN AAJ PEHLI BAAR





 HUMNE PEE RAKHI HAI