Wednesday, August 17, 2022

Python Interview Questions

 


1. list vs tuple ?

2. Decorator ? give an example

3. List Comprehension , Dict comprehension , and generator ?

4. how memory manged in python ?

5. diff beween generator and iterator ? yield

6. __init__ , __iter__ , __next__

7.module vs library

8. range vs xrange

9.Python Anonymous/Lambda Function

10. inbuild datat types - mutable immutable

11. ternary operator , global local

12.inheritance, classses,objeects , self , abstraction ,encpasulation

13. pickling and unpickling

14. list,tuple,set , dicts . empty initilaizations , diffrent methods

15. *arhgs vs **kwargs

16. open and with statemnt

17. read and write files in pythpn

18. pythonpath, interpreter, garabge collector , py vs .pyc

19. expcetoion, try execpet, finally

20. python2 vs python3 , pip , 

21. get all keys in dict

22. diamond problem ?? super() 

23. array , slicing , string manipulation , arry vs List

24. how concatemate tow tuples ??

15 , _a , __a ,__a__ ?

16. copy and delete dict

27.Lambda func , higher order func

18. multi threading and multiprocessing in python

29. GIL , global interpreter lock

30. class and object,namespaces 

31 unit tests

32 map,reduve

33. monkey patching in python

34. shallow copy vs deep copy

25 operator overloading and dunder methods


bytearry vs bytes , memoryview

=====================================================


https://www.fullstack.cafe/blog/advanced-python-interview-questions

https://www.zeolearn.com/interview-questions/python


Saturday, April 1, 2017

Turn on Bluetooth Acer Aspire E 15

1. Fn +F3
2. Go to device Driver .Then Enable
3.The Blutooth icone will be now shown on System tray
4. Single click


Thursday, January 7, 2016

program to check if a cordinates fall in black or white box of an infinite chess board

Consider the image as an infinite chessboard.With each block of 4 units.The boxes are colored alternatively black and white.

Now given the x and y co-ordinates of any point on this board we have to decide whether it lies inside a white box or back square.The points on border will be considered as  present in black.

All blue dots are inside black square while the whites are in white square.




#include <cstdlib>
#include <iostream>
#define steps 4
using namespace std;


void insideblack(int x,int y);

int main(int argc, char *argv[])
{
     insideblack(5,4);
   
    system("PAUSE");
    return EXIT_SUCCESS;
}
void insideblack(int x,int y)
{      
     bool inx,iny,xyin;
     //for x cordinates
     if(x<=steps)
     {
       //cout<<x<<" is on black x-axis"<<endl;
       inx=true;
     }
     else
     {        
          if(  ((x/steps)%2 !=0 ) && ( x%4 != 0))
          {
              //cout<<x<<" is on white x-axis"<<endl;
              inx=false;
          }
           else
           {
              //cout<<x<<" is on black x-axis"<<endl;
              inx=true;
           }
       }
   
     //for y cordinates
     if(y<=steps)
     {
       //cout<<y<<" is on black x-axis"<<endl;
       iny=true;
     }
     else
     {        
          if(  ((y/steps)%2 ==0 ) && ( y%4 != 0))
          {
              //cout<<y<<" is on black y-axis"<<endl;
              iny=true;
          }
          else
          {
               //cout<<y<<" is on white y-axsis"<<endl;
               iny=false;
          }
     }
     if(inx==true && iny==true)
     {
        xyin=true;
     }
     if(inx==true && iny==false)
     {
        if(x>0 && x%steps ==0) //border cases
        {xyin=true;}
        else
        {xyin=false;}
     }
     if(inx==false && iny==true)
     {
        if(y>0 && y%steps==0)//border condition
        {
           xyin=true;
        }
        else
        {
           xyin=false;
        }
     
     }
     if(inx==false && iny==false)
     {
        xyin=true;
     }
     
       if(xyin==true)
       cout<<"cordinates in black region"<<endl;
       else
       cout<<"cordinates in white region"<<endl;
           
}

Tuesday, October 20, 2015

C++ interview Questions for Experinced persons



1. overload new operater.
2. Difference between Op new and new operator
3. Explain placement new and why n when it is used
4. is there a placement delete.
5. Explain the error when new fails
6. malloc vs new
7.what is name mangling
8.what are proxy objects ?
9.what is a local class ,sub class ,nested clasd
10.what is object slicing.
11. What is name hiding
12. Explain vtable in detail
       http://www.go4expert.com/articles/virtual-table-vptr-t16544/
       http://www.learncpp.com/cpp-tutorial/125-the-virtual-table/
13.what is a conversion constructor
14.explain explicit constructor
15.copy constructor vs overloaded assignment operator
16.what are class invariants
17.implement a final class in cpp
18.Write a singleton pattern.is it threadsafe ?where it is used.
19.how stl map is implemented internally??
20.how vector allocate memory or how it works internally.can you write your own vector ?
21.what are smart pointers .unique_ptr vs auto_ptr vs shared_ptr?
22. Queue vs priority queue.can you implement or write your own priority queue.
23. Vector vs list vs deque vs map. Which one should u use under what situation
24.what are function pointers , call back functions. What are advantages
25.list x ;list x(); what is the difference here
26.what is synchronous and asynchronous calls/functions or operations
27.what tools u have used for performace checking.how u detect memory leaks.
   Explain how you can detect memory leak,memory corruption.what is dangling pointer
28.have u worked with gdb ,dbx,valgrind ??
29.overloading on const
30.design patterns used in ur project. Explain and write abstract factory,visitor etc
31.how to remove duplicates from vector with single traversal.
32.why private constructor is used. how to handle exceptions in a constructor ?and do we need to handle exceptions in destructor ??

https://isocpp.org/wiki/faq/exceptions#selfcleaning-members

33.How iterator invalidation works in vector,dq,list
34.efficient method of removing odd elements from vector
33.how to sort a vector containing pair elements
34.how to add an element to the front of a vector
35.difference between map::find() vs map::operator[ ]
36.are pure virtual methods allowed in a template class
37.can we have static virtual function
38. Function pointer vs function objects
39.map vs hash_map
40.why should you use obj.empty() over (obj.size() ==0) to check emptiness
41.difference between conversion function and overloaded function call operator
42. Implement pre and post increment operator.
43.how reserve() , capacity() and resize() works in vector
44.what is infamous swap trick on vector ? How to downsize a vector
45.should we use global find algorithm or member function find() for map/set ?
46.how to call/use base class virtual function by a derived class which has already ovrridden it ?
47.can virtual function be private ??
48.issues with pass by value of a class object
49. Int *p=null ; int &p=null ; are they  wrong/correct ??
50.pimpl idiom
51.How to initialize const member variables of a class ??
52. this vs *this
      http://stackoverflow.com/questions/2750316/this-vs-this-in-c
53.calculate the Size of object of a class
54.Write a non-inheritable class(final class)
      http://www.geeksforgeeks.org/simulating-final-class-in-c/
      http://stackoverflow.com/questions/1366441/final-class-in-c

55.Smart pointers , boost::shared_ptr or std::unique_ptr
  
std::shared_ptr<int> p1(new int(5));
std::shared_ptr<int> p2 = p1; //Both now own the memory.

p1.reset(); //Memory still exists, due to p2.
p2.reset(); //Deletes the memory, since no one else owns the memory.


56. New features in c++14
   auto and lambda,std::move constructor ,forward
57.Why do I need to return *this in an assignment operator function?
   To make assignment such as (obj3 = obj2) = obj1; to work.
58.Cache locality,SFINAE 
59.What is the difference between std::vector<int> x; and std::vector<int> x() ?
  First one declares a variable x of type std::vector. Second one declares a function x which returns       std::vector.
60. How to initialize constant and reference member variable?
  Using initialization list.
61.How would you delete object of singleton class?
  we can follow is “Reference counting” mechanism
62. factory vs Abstract factory
    http://www.codeproject.com/Articles/492900/From-No-Factory-to-Factory-Method
   http://corey.quickshiftconsulting.com/blog/first-post
63.How thread synchronization done for pthreads
     http://www.bogotobogo.com/cplusplus/multithreading_pthread.php
64.How to debug threads in dbx/gdb
65.How to use c code in c++
65.What will the sizes of base and derived class object.
http://www.go4expert.com/articles/size-cpp-class-object-t16676/

class Base
{       char ch;
         int value;
        static double db;
    public:
        Base(){}
        virtual ~Base(){}      
        virtual void func() {}
};

class Derived : virtual public Base
{     int d1;
    public:
       void func(){}      
       virtual void func2(){}
};

Ans: Base b is of size=1byte char+3byte padding+4byte int+1 byte vtable pointer=12bytes
        Derived d=(12 bytes of Base)+ 4 byte Int + 4 Byte for Virtual derivation =20 bytes

66. Write your own C++ like exceptional Handling in c.(oracle second round)

http://www.on-time.com/ddj0011.htm
http://stackoverflow.com/questions/4448677/can-a-c-program-handle-c-exceptions

67.Write a c program to dump data from a table having 20K records.;without using Pro*C.
  OCI ??
    https://github.com/vrogier/ocilib
    https://vrogier.github.io/ocilib/doc/html/group___ocilib_c_api_statements.html
68.How to create rest APIs in c.
69.Implement Stack using two queues.
  http://stackoverflow.com/questions/688276/implement-stack-using-two-queues
  http://www.geeksforgeeks.org/implement-stack-using-queue/

Wednesday, October 14, 2015

Simple wordpress AJAX submit example


Follow these simple steps.

1. Create a button on the page i.e. maybe on index page

       <input class="ajax-link" type="button" value="AJAXSUBMIT">

2. we will pass the text data "client side data" and get the response from server as "received data:" "client side"


3. create a file myajax.js under themes 'js' folder having below content

    jQuery(document).ready( function($) {
$(".ajax-link").click( function() {
var data = {
action: 'test_response',
                        post_var: 'client side '
};
// the_ajax_script.ajaxurl is a variable that will contain the url to the ajax processing file
$.post(the_ajax_script.ajaxurl, data, function(response) {
alert(response);
});
return false;
});
});



4. open the functions.php file from themes folder
5. Add the javascript and localize the ajaxurl


function test_ajax_load_scripts() {
// load our jquery file that sends the $.post request
wp_enqueue_script( "ajax-test",get_template_directory_uri() . '/js/myajax.js', array( 'jquery' ) );

// make the ajaxurl var available to the above script
wp_localize_script( 'ajax-test', 'the_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
}
add_action('wp_print_scripts', 'test_ajax_load_scripts');

 
6. Add the below in functions.php to process ajax data from cleint side

function text_ajax_process_request() {
// first check if data is being sent and that it is the data we want
  if ( isset( $_POST["post_var"] ) ) {
// now set our response var equal to that of the POST var (this will need to be sanitized based on what you're doing with with it)
$response = $_POST["post_var"];
        $server_text= "received data: ";
// send the response back to the front end
echo $server_text.$response;
die();
}
}
add_action('wp_ajax_test_response', 'text_ajax_process_request');
add_action('wp_ajax_nopriv_test_response', 'text_ajax_process_request');

Here is the result


Monday, September 21, 2015

PL SQL Interview questions

1.Can we have a commit statement inside a trigger? if no why cant we?
2.How to sum negative and positive numbers from a single column ?
3.select strings containing % in a column.
4.Why is self-join required ?
5.differentiate between Where and Having ?
6.Find the Nth largest value in a column
8.Select alternate records from a table
9.select distinct records from a table,based on one column
10.delete duplicate rows in a table
11.What is a sequence?
12.How to access a sequence ?
13.What is a SYNONYM? in which cases do we generally use synonyms?
14.Advantages of synonym?
15.Will the synonym work when the parent table name is changed or table is dropped and created again??

16.difference between PK and Unique Key

17.differentiate between char and varchar

18.procedures are give better performance ??
    do we need to compile procedures ?

19.diff between ,
  select count(*) from table
  select count(column1) from table

20.Can we use commit inside the trigger? If not then how can we save the transaction made by the trigger?

21. What is the difference between "IS" and "AS" while creating procedure. Ex:- create procedure IS or AS

22. what is the difference between stored procedures and stored functions in ORACLE.How are they invoked.

23. How can we call stored procedures inside store procedures?

24. What is stored procedure?How to invoke them ?can we use them in dml statement ??

25. Explain about the process which takes place to execute a Stored routine?

26.Where the procedures are stored in database?

28. Explain about the difficulties faced by the database developer in implementing pre compiled statements?

29. how many types of stored procedure?

30. What is the difference between stored procedures and stored functions in ORACLE

31. Explain the benefits of running stored procedure on a database engine?

32. How one calls DDL statement using stored procedures in Oracle? Why can't we write ddl statement directly into the PL/SQL block ?

CREATE OR REPLACE PROCEDURE test IS
BEGIN
    truncate table table_name; // error
END test;
/
But,

CREATE OR REPLACE PROCEDURE test IS
BEGIN
    execute immediate 'truncate table table_name'; // works fine
END test;
/

Data definition language (DDL) statements such as CREATE, DROP, GRANT, and REVOKE can be executed within PL/SQL program units.

When using EXECUTE IMMEDIATE, remember that any DDL operations you execute will implicitly COMMIT the current transaction.

33. Are triggers fired during DDL statements?Say you have a "on delete" trigger. What will happen when you fire a delete?

Trigger will be fired and trigger body will be executed
34. What are external procedures ? Why and when they are used?
35. 
State the different extensions for stored procedures?
Does storing of data in stored procedures increase the access time? Explain?
What is cursors?
What are the uses of stored procedure?

Explain about recursive stored procedures?

PL/SQL allows sub procedures or functions to be called recursively. The tutorial example below shows you how to calculate factorial values with a recursive sub function:

CREATE OR REPLACE PROCEDURE FACTORIAL_TEST AS              
  FUNCTION FACTORIAL(N NUMBER)                             
    RETURN NUMBER AS                                       
  BEGIN            
    IF N <= 1 THEN 
      RETURN 1;    
    ELSE           
      RETURN N*FACTORIAL(N-1);                             
    END IF;        
  END;             
BEGIN              
  DBMS_OUTPUT.PUT_LINE('3! = ' ||    TO_CHAR(FACTORIAL(3)));
  END;

/  


What Is the Scope of a Local Variable?
The scope of a variable can be described with these rules:
A variable is valid within the procedure or function where it is defined.
A variable is also valid inside a sub procedure or function defined.
If a variable name is collided with another variable in a sub procedure or function, this variable becomes not visible in that sub procedure or function.

CREATE OR REPLACE PROCEDURE PARENT AS
   X CHAR(10) := 'FYI';
   Y NUMBER := 999999.00;
   PROCEDURE CHILD AS
     Y CHAR(10) := 'CENTER';
     Z NUMBER := -1;
   BEGIN
     DBMS_OUTPUT.PUT_LINE('X = ' || X); -- X from PARENT
     DBMS_OUTPUT.PUT_LINE('Y = ' || Y); -- Y from CHILD
     DBMS_OUTPUT.PUT_LINE('Z = ' || TO_CHAR(Z));
   END;
 BEGIN
   DBMS_OUTPUT.PUT_LINE('X = ' || X); -- X from PARENT
   DBMS_OUTPUT.PUT_LINE('Y = ' || TO_CHAR(Y));
   -- DBMS_OUTPUT.PUT_LINE('Z = ' || TO_CHAR(Z));
   CHILD;
 END;

 /


what is the Difference between View and Stored Procedure?
Explain about the implementation of stored procedures?

C Interview Questions



1.Difference between malloc and calloc
2.Write your own strcpy,strcmp,atoi function


   char *my_strcpy(char dest[], const char source[])
  {
          int i = 0;
        while (source[i] != '\0')
        {
               dest[i] = source[i];
               i++;
       }
     dest[i] = '\0';
      return(dest);
}

2.1 Program to Check if a Given String is Palindrome

// A function to check if a string str is palindrome
void isPalindrome(char str[])
{
    // Start from leftmost and rightmost corners of str
    int l = 0;
    int h = strlen(str) - 1;

    // Keep comparing characters while they are same
    while (h > l)
    {
        if (str[l++] != str[h--])
        {
            printf("%s is Not Palindrome\n", str);
            return;
        }
    }
    printf("%s is palindrome\n", str);
}

2.2 Program t check if number is palindrome
http://www.geeksforgeeks.org/check-if-a-number-is-palindrome/
3. Write a program to delete a node from Linked List
4.Write a program to reverse a linked List with recursion and w/o recurssion.
5. Program to find the Nth Node from end in single traversal
6.Write a function to accept variable number of arguments
7.different storage classes in c
8.Program to write a daemon in c
9.What is structure padding in C,size of a structire variable.
10. Advantage of function pointers
11.How to find linked list has loop
12.find the middle element of a linked list
13.write a function to check if a string/number is palindrome
14.Difference between reference variable and pointer variable
15.Difference between string a character arrays
16.Constant pointer and pointer to a constant
17.describe memory layout of a c/c++ program.i.e. heap/stack/static storage etc
18.Difference between character array and character pointer
      char arr[]="hello";
      char *s="hello";
19. memset vs memcpy.
20.What is a dangling pointer.give an example.Example of cases when memory leak might hppen
21.Mutable vs Volatile variables
22.Why is volatile needed in c
23. C Program to Check whether two Strings are Anagrams.(with sort and without sorting them)
24What is stack unwinding,context switching,Segmentation Fault
   http://www.bogotobogo.com/cplusplus/stackunwinding.php
   http://www.geeksforgeeks.org/stack-unwinding-in-c/
25. Sorting Algorithms along with time complexities- Selection,Insertion,Bubble,Quick,Merge
26.How to use realloc function as free and malloc or inplace of free and malloc
27.Programm or macro for - setting a bit,toggling a bit,clear and checking a bit using bitwise operators
28. Strlen vs sizeof op in c
29. implement strlen function in C
30.Write a program to check whether the given number is a prime.
31.Write a program to generate the Fibonacci series
32.Difference in reading a text file and a Binary file ?
33.Break vs continue
34.Why is it safer to use fgets() over gets()
35.difference between printf ,fprintf,sprintf
36.prorag to check liitle endian vs big endian
37.What is the difference between NULL, '\0' and 0
http://stackoverflow.com/questions/1296843/what-is-the-difference-between-null-0-and-0

38.write a variable argument function
   http://www.tutorialspoint.com/cprogramming/c_variable_arguments.htm

40.What does the below codes do ??
   a. void my_strcat(char *dest, char *src)
{
  (*dest)? my_strcat(++dest, src): (*dest++ = *src++)? my_strcat(dest, src): 0 ;
}

b. int my_strcmp(char *a, char *b)
{
  return (*a == *b && *b == '\0')? 0 : (*a == *b)? my_strcmp(++a, ++b): 1;
}

41.Dynamically allocate array of strings in c

 
    int num,len,i;
    char temp[50],ch;
    char **ptr;
    printf("enter num of strings u want\n");
    scanf("%d",&num);
    ptr=(char **)malloc(sizeof(char *) * num);

    for(i=0;i <num;i++)
    {

       printf("enter the string\n");
       scanf("%s",temp);
       len=strlen(temp)+1;
       ptr[i]=(char*)malloc(len);
       strcpy(ptr[i],temp);

    }

42. Difference between global static variable vs normal global variable

    static int var1;
           int var2;
    int main(){}

   var2 has external linkage while var1 has internal linkage (visible to that file only)

43. Multi threading c (pthreads)

44. System programming(IPC) - sockets,sharedmem etc
45. what is the difference between popen() and system() in C ?
46. in C Language,which is better(faster n safer) : Better sprintf ,strcpy or memcpy???

47. How to debug a program running in remote machine ?
     gdbserver

48.What will be the output of below code snippet?
   int x=0; 
  while (x<3) {
    cout<<x<<std::endl;
    x = x++;
  }
 ANS: Infinite loop

49. What is heap corruption ?
50. which layout the command line arguments stored in memory ? heap , stack or somewhere else ?
51. describe how heap is designed ? 

52.  socket programming -- Listen socket call
   https://stackoverflow.com/questions/60181148/what-is-the-purpose-of-listen-in-socket-programming
   https://www.gnu.org/software/libc/manual/html_node/Accepting-Connections.html

53. System calls in c ==> 
   A system call is a request for service that a program makes of the kernel
   System calls are sometimes called kernel calls.

    https://www.gnu.org/software/libc/manual/html_node/System-Calls.html
  https://www.geeksforgeeks.org/input-output-system-calls-c-create-open-close-read-write/