Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

Showing posts with label Interview Question. Show all posts
Showing posts with label Interview Question. Show all posts
1:00 pm

PHP interview questions and answers for freshers

Welcome !!!. In this section we are providing you some frequently asked PHP Interview Questions which will help you to win interview session easily. Candidates must read this section,Then by heart the questions and answers. Also, review sample answers and advice on how to answer these typical interview questions. PHP is an important part of the web world, and every web developer should have the basic knowledge in PHP.Common PHP interview questions, which should help you become a best PHP codder. We hope you find these questions useful. If you are an interviewer, Take the time to read the common interview questions you will most likely be asked.

  1. What is PHP?                                                                                                                            PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famus CMS of php.It is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning

  2. What is the use of "echo" in php?                                                                                               It is used to print a data in the webpage, Example: <?php echo 'Car insurance'; ?> , The following code print the text in the webpage

  3. How to include a file to a php page?                                                                                         We can include a file using "include() " or "require()" function with file path as its parameter.

  4. What's the difference between include and require?                                                                 If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.
  5. require_once(), require(), include().What is difference between them?                                    require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

  6. Differences between GET and POST methods ?                                                                    We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method .

  7. How to declare an array in php?                                                                                                       Eg : var $arr = array('apple', 'grape', 'lemon');

  8. What is the use of 'print' in php?                                                                                           This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.

    Example print('PHP Interview questions');
    print 'Job Interview ');


  9. What is use of in_array() function in php ?                                                                                      in_array used to checks if a value exists in an array

  10. What is use of count() function in php ?                                                                                     count() is used to count all elements in an array, or something in an object

  11. What's the difference between include and require?                                                               It's how they handle failures. If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.

  12. What is the difference between Session and Cookie?                                                            The main difference between sessions and cookies is that sessions are stored on the server, and cookies are stored on the user's computers in the text file format. Cookies can't hold multiple variable while session can hold multiple variables..We can set expiry for a cookie,The session only remains active as long as the browser is open.Users do not have access to the data you stored in Session,Since it is stored in the server.Session is mainly used for login/logout purpose while cookies using for user activity tracking
  13. How to set cookies in PHP? 
     Setcookie("sample", "ram", time()+3600);

  14. How to Retrieve a Cookie Value?                                                                                                eg : echo $_COOKIE["user"];

  15. How to create a session? How to set a value in session ? How to Remove data from a session?                                                                                                                                            Create session : session_start();
    Set value into session : $_SESSION['USER_ID']=1;
    Remove data from a session : unset($_SESSION['USER_ID'];.

  16. what types of loops exist in php? 
     for,while,do while and foreach (NB: You should learn its usage)

  17. Note:-
    MySQLi (the "i" stands for improved) and PDO (PHP Data Objects) are the MySQL extensions used to connect to the MySQL server in PHP5 or verions, MySQL extension was deprecated in 2012.
    MySQLi only works with MySQL databases whereas PDO will works with 12 other Database systems
    I recommend PDO because, if you want to choose another database instead of MySQL, then you only have to change the connection string and a few queries. But if you are using MySQLi you will need to rewrite the entire code

  18. How to create a mysql connection?
    Example (PDO)
    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";

    try {
        $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
        // set the PDO error mode to exception    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        echo "Connected successfully";
        }
    catch(PDOException $e)
        {
        echo "Connection failed: " . $e->getMessage();
        }
    ?>

    Example (MySQLi Object-Oriented)
    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "myDB"; // Optional

    // Create connection$conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";
    ?>

    Example (MySQLi Procedural)
    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "myDB"; // Optional


    // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname);

    // Check connection if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "Connected successfully";
    ?>

  19. How to execute an sql query? How to fetch its result ?
    Example (MySQLi Object-oriented)

    $sql = "SELECT id, firstname, lastname FROM MyGuests";
    $result = $conn->query($sql); // execute sql query

    if ($result->num_rows > 0) {
        // output data of each row
        while($row = $result->fetch_assoc()) { // fetch data from the result set
            echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
        }
    } else {
        echo "0 results";
    }

    Example (MySQLi Procedural)

    $sql = "SELECT id, firstname, lastname FROM MyGuests";
    $result = mysqli_query($conn, $sql); // execute sql query

    if (mysqli_num_rows($result) > 0) {
        // output data of each row
        while($row = mysqli_fetch_assoc($result)) { // fetch data from the result set
            echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
        }
    } else {
        echo "0 results";
    }
    Example (PDO)

    Method 1:USE PDO query method
    $stmt = $db->query('SELECT id FROM Employee');  
    $row_count = $stmt->rowCount();  
    echo $row_count.' rows selected';

    Method 2: Statements With Parameters
    $stmt = $db->prepare("SELECT id FROM Employee WHERE name=?");  
    $stmt->execute(array($name));  
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
     
  20. Write a program using while loop
    <?php
    $x = 1;

    while($x <= 5) {
        echo "The number is: $x <br>";
        $x++;
    }
    ?>
  21. How we can retrieve the data in the result set of MySQL using PHP?
    MySQLi methods
    • 1. mysqli_fetch_row
    • 2. mysqli_fetch_array
    • 3. mysqli_fetch_object
    • 4. mysqli_fetch_assoc
    PDO methods
    • 1. PDOStatement::fetch(PDO::FETCH_ASSOC)
    • 2. PDOStatement::fetch(PDO::FETCH_OBJ)
    • 3. PDOStatement::fetch()
    • 4. PDOStatement::fetch(PDO::FETCH_NUM).
    •  
  22. What is the use of explode() function ? Syntax : array explode ( string $delimiter , string $string [, int $limit ] );
    This function breaks a string into an array. Each of the array elements is a substring of string formed by splitting it on boundaries formed by the string delimiter.

  23. What is the difference between explode() and str_split() functions? str_split function splits string into array by regular expression. Explode splits a string into array by string.
  24. What is the use of mysql_real_escape_string() function? It is used to escapes special characters in a string for use in an SQL statement

  25. Write down the code for save an uploaded file in php.
    <?php
    if ($_FILES["file"]["error"] == 0)
    {
    move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    ?>
  26. How to create a text file in php?
    <?php
    $filename = "/home/user/guest/newfile.txt";
    $file = fopen( $filename, "w" );
    if( $file == false )
    {
    echo ( "Error in opening new file" ); exit();
    }
    fwrite( $file, "This is a simple test\n" );
    fclose( $file );
    ?>
  27. How to strip whitespace (or other characters) from the beginning and end of a string ? The trim() function removes whitespaces or other predefined characters from both sides of a string.
  28. What is the use of header() function in php ? 
     The header() function sends a raw HTTP header to a client browser.Remember that this function must be called before sending the actual out put.For example, You do not print any HTML element before using this function.
4:22 pm

C++ Interview Questions


C++ Interview Questions


1.) What is the full form of OOPS?
Object Oriented Programming System.

2.) What is a class?
Class is a blue print which reflects the entities attributes and actions. Technically defining a class is designing an user defined data type.

3.) What is an object?
An instance of the class is called as object.

4.) List the types of inheritance supported in C++.
Single, Multilevel, Multiple, Hierarchical and Hybrid.

5.) What is the role of protected access specified ?If a class member is protected then it is accessible in the inherited class. However, outside the both the private and protected members are not accessible.

6.) What is encapsulation?
The process of binding the data and the functions acting on the data together in an entity (class) called as encapsulation.

7.) What is abstraction?
Abstraction refers to hiding the internal implementation and exhibiting only the necessary details.

8.) What is inheritance?
Inheritance is the process of acquiring the properties of the existing class into the new class. The existing class is called as base/parent class and the inherited class is called as derived/child class.

9.) Explain the purpose of the keyword volatile.
Declaring a variable volatile directs the compiler that the variable can be changed externally. Hence avoiding compiler optimization on the variable reference.

10.) What is an inline function?
A function prefixed with the keyword inline before the function definition is called as inline function. The inline functions are faster in execution when compared to normal functions as the compiler treats inline functions as macros.

11.) What is a storage class?
Storage class specifies the life or scope of symbols such as variable or functions.

12.) Mention the storage classes names in C++.
The following are storage classes supported in C++
auto, static, extern, register and mutable

13.) What is the role of mutable storage class specifier?
A constant class object’s member variable can be altered by declaring it using mutable storage class specified. Applicable only for non-static and non-constant member variable of the class.

14.) Distinguish between shallow copy and deep copy.
Shallow copy does memory dumping bit-by-bit from one object to another. Deep copy is copy field by field from object to another.
Deep copy is achieved using copy constructor and or overloading assignment operator.

15.) What is a pure virtual function?
A virtual function with no function body and assigned with a value zero is called as pure virtual function.

16.) What is an abstract class in C++?
A class with at least one pure virtual function is called as abstract class. We cannot instantiate an abstract class.

17.) What is a reference variable in C++?
A reference variable is an alias name for the existing variable. Which mean both the variable name and reference variable point to the same memory location. Therefore updation on the original variable can be achieved using reference variable too.
18.) What is role of static keyword on class member variable?
A static variable does exist though the objects for the respective class are not created.
Static member variable share a common memory across all the objects created for the respective class. A static member variable can be referred using the class name itself.
Explain the static member function.
A static member function can be invoked using the class name as it exists before class objects comes into existence. It can access only static members of the class.

19.) Name the data type which can be used to store wide characters in C++.
wchar_t

20.) What are/is the operator/operators used to access the class members?
Dot (.) and Arrow ( -> )

21.) Can we initialize a class/structure member variable as soon as the same is defined?
No, Defining a class/structure is just a type definition and will not allocated memory for the same.

22.) What is the data type to store the Boolean value?
bool, is the new primitive data type introduced in C++ language.

23.) What is function overloading?
Defining several functions with the same name with unique list of parameters is called as
function overloading.

24.)What is operator overloading?Defining a new job for the existing operator w.r.t the class objects is called as operator overloading.

25.) Do we have a String primitive data type in C++?
No, it’s a class from STL (Standard template library).

26.) Name the default standard streams in C++.
cin, cout, cerr and clog.

27.) Which access specifier/s can help to achive data hiding in C++?
Private & Protected.

28.) When a class member is defined outside the class, which operator can be used to associate the function definition to a particular class?
Scope resolution operator (::)

29.) What is a destructor? Can it be overloaded?
A destructor is the member function of the class which is having the same name as the class name and prefixed with tilde (~) symbol. It gets executed automatically w.r.t the object as soon as the object loses its scope. It cannot be overloaded and the only form is without the parameters.

30.) What is a constructor?
A constructor is the member function of the class which is having the same as the class name and gets executed automatically as soon as the object for the respective class is created.

31.) What is a default constructor? Can we provide one for our class?
Every class does have a constructor provided by the compiler if the programmer doesn’t provides one and known as default constructor. A programmer provided constructor with no parameters is called as default constructor. In such case compiler doesn’t provides the constructor.

32.) Which operator can be used in C++ to allocate dynamic memory?
‘new’ is the operator can be used for the same.

33.) What is the purpose of ‘delete’ operator?
‘delete’ operator is used to release the dynamic memory which was created using ‘new’ operator.

34.) Can I use malloc() function of C language to allocate dynamic memory in C++?
Yes, as C is the subset of C++, we can all the functions of C in C++ too.

35.) Can I use ‘delete’ operator to release the memory which was allocated using malloc() function of C language?
No, we need to use free() of C language for the same.

36.) What is a friend function?
A function which is not a member of the class but still can access all the member of the class is called so. To make it happen we need to declare within the required class following the keyword ‘friend’.

37.) What is a copy constructor?
A copy constructor is the constructor which take same class object reference as the parameter. It gets automatically invoked as soon as the object is initialized with another object of the same class at the time of its creation.

3:22 pm

C Programming Interview Questions



C Programming Interview Questions



1) What is C language?
C is a mid level and procedural programming language. 

2) Why C is known as a mother language?

C is known as a mother language because most of the compilers, kernals and JVMs are written in C language. 

3) Why C is called a mid level programming language?

It supports the feature of both low-level and high level languages that is why it is known as a mid level programming language.

4) Who is the founder of C language?

Dennis Ritchie.

5) When C language was developed?

C language was developed in 1972 at bell laboratories of AT&T.

6) What are the features of C language?

The main features of C language are given below:
Simple
Portable
Mid Level
Structured
Fast Speed
Memory Management
Extensible


7) What is the use of printf() and scanf() functions?

The printf() function is used for output and scanf() function is used for input.

8) What is the difference between local variable and global variable in C?

Local variable: A variable which is declared inside function or block is known as local variable.
Global variable: A variable which is declared outside function or block is known as global variable.

int value=50;//global variable
void function1(){
int x=20;//local variable
}
  


9) What is the use of static variable in C?

A variable which is declared as static is known as static variable. The static variable retains its value between multiple function calls.

void function1(){
int x=10;//local variable
static int y=10;//static variable
x=x+1;
y=y+1;
printf("%d\n",x);//will always print 11
printf("%d\n",y);//will always increment value, it will print 11, 12, 13 and so on
}
  


10) What is the use of function in C?

A function in C language provides modularity. It can be called many times. It saves code and we can reuse the same code many times. 

11) What is the difference between call by value and call by reference in C?
We can pass value to function by one of the two ways: call by value or call by reference. In case of call by value, a copy of value is passed to the function, so original value is not modified. But in case of call by reference, an address of value of passed to the function, so original value is modified. 

12) What is recursion in C?
Calling the same function, inside function is known as recursion. For example:
void function1(){
function1();//calling same function
}
  

13) What is array in C?.

Array is a group of similar types of elements. It has contiguous memory location. It makes the code optimized, easy to traverse and easy to sort.

14) What is pointer in C?
A pointer is a variable that refers to the address of a value. It makes the code optimized and makes the performance fast. 

15) What are the usage of pointer in C?
Accessing array elements
Dynamic memory allocation
Call by Reference
Data Structures like tree, graph, linked list etc.

16) What is NULL pointer in C?
A pointer that doesn't refer to any address of a value but NULL, is known as NULL pointer.
For example:
int *p=NULL;  

17) What is far pointer in C?

A pointer which can access all the 16 segments (whole residence memory) of RAM is known as far pointer.

18) What is dangling pointer in C?
If a pointer is pointing any memory location but meanwhile another pointer deletes the memory occupied by first pointer while first pointer still points to that memory location, first pointer will be known as dangling pointer. This problem is known as dangling pointer problem.

19) What is pointer to pointer in C?In case of pointer to pointer concept, one pointer refers to the address of another pointer. 

20) What is static memory allocation?
In case of static memory allocation, memory is allocated at compile time and memory can't be increased while executing the program. It is used in array.


21) What is dynamic memory allocation?
In case of dynamic memory allocation, memory is allocated at run time and memory can be increased while executing the program. It is used in linked list.


22) What functions are used for dynamic memory allocation in C language?
malloc()
calloc()
realloc()
free()

23) What is the difference between malloc() and calloc()?

malloc(): The malloc() function allocates single block of requested memory. It has garbage value initially.
calloc(): The calloc() function allocates multiple block of requested memory. It initially initializes all bytes to zero.

24) What is structure?

Structure is a user-defined data type that allows to store multiple types of data in a single unit. It occupies the sum of memory of all members. 

25) What is union?
Like Structure, union is a user-defined data type that allows to store multiple types of data in a single unit. But it doesn't occupies the sum of memory of all members. It occupies the memory of largest member only. 

26) What is auto keyword in C?
In C, every local variable of a function is known as automatic (auto) variable. Let's explain with an example:
void f()
{
int i ;
auto int j;
}  
Here, both 'i' and 'j' variables are automatic variables.
Note: A global variable can't be an automatic variable.

27) What is the purpose of sprintf() function?
It is used to print the formatted output into char array.

28) Can we compile a program without main() function?
Yes, we can compile but it can't be executed.
But, if we use #define, we can compile and run C program without using main() function.
For example:
#include<stdio.h> 
#define start main 
void start() { 
   printf("Hello"); 
}    

29) What is token?
Token is an identifier. It can be constant, keyword, string literal etc.

30) What is command line argument?
The argument passed to the main() function while executing the program is known as command line argument.
For example:
main(int count, char *args[]){
//code to  be executed
}
  

31) What is the acronym for ANSI?

American National Standard Institute.

32) What is the difference between getch() and getche()?
The getch() function reads a single character from keyboard. It doesn't uses any buffer, so entered data is not displayed on the output screen.
The getche() function reads a single character from keyword but data is displayed on the output screen. Press Alt+f5 to see the entered character.

33) What is new line escape sequence?
The new line escape sequence is represented by "\n". It inserts a new line on the output screen.

34) Who is the main contributor in designing the C language after Dennis Ritchie?
Brain Kernighan.

35) What is the difference between near, far and huge pointers?
A virtual address is composed of selector and offset.
A near pointer doesn't have explicit selector whereas far and huge pointers have explicit selector. When you perform pointer arithmetic on far pointer, selector is not modified but in case of huge pointer it can be modified.
These are the non-standard keywords and implementation specific. These are irrelevant in modern platform.

36) What is the maximum length of an identifier?It is 32 characters ideally but implementation specific.

37) What is typecasting?
Converting one data type into another is known as typecasting. For example:
float f=3.4;
int a=(int)f;//typecasting
  

38) What are the functions to open and close file in C language?
The fopen() function is used to open file whereas fclose() is used to close file.

39) Can we access array using pointer in C language?
Yes, by holding the base address of array into pointer, we can access the array using pointer.

40) What is infinite loop?
A loop running continuously for indefinite number of times is called infinite loop.
I
nfinite For Loop:
for(;;)
{
//code to be executed
}  


Infinite While Loop:
while(1)
{
//code to be executed
 Infinite Do-While Loop:
do
{
//code to be executed
}while(1);