Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Sunday, March 21, 2010

57

5
4
7
6
1
0
3
2
13
12

  • Write a program to print the above sequence.

  • Logical Hint: Use bitwise operator.

    Program:
    int main()
    {
    int i;
    for(i=0;i<10;i++)
    {
    printf("%d",i^5);
    }
    return 0;
    }

    Some Interview Questions

  • Minimum no. of queues needed to implement the priority queue?
    Ans:Two

  • What are the notation used in Evaluation of Arithmetic Expressions using prefix and prefix forms?
    Ans: Reverse polish notations and Polish

  • In tree construction which is the suitable efficient data structure?
    Ans: Linked List

  • In tree structure ,which is,efficient considering space and time complexities?
    Ans:Complete Binary Tree

  • What Operator performs pattern matching?
    Ans:LIKE

  • What are the different phases of transaction?
    ans: Redo &undo
  • Bit counting

    int main()
    {
    int function(int n);
    int i,n=2,b;
    clrscr();
    for(i=0;i<100;i++)
    {
    b=function(i);
    if(b==n)
    {
    printf("%d",i);
    }
    }
    getch();
    return 0;
    }
    int function(int n)
    {
    int i=0;
    while(n!=0)
    {
    if(n&01)
    {
    i++;
    }
    n>>=1;
    }
    return i;
    }

    Output :


    3
    5
    6
    9
    10
    12
    17
    18
    20
    24
    33
    34
    36
    40
    48
    65
    66
    68
    72
    80
    96

    Constant Pointer Vs Pointer Constant

    Do you think that the terms Pointer Constant and Constant Pointer are the same?

    If your answer is 'YES' then I can Prove it wrong through The below example...!



    int main()
    {
    int i=2;
    int const *p;
    p=&i;
    printf("%d",*p);
    return 0;
    }

    int main()
    {
    int i=2;
    int *const p=&i;
    *p=3;
    printf("%d",*p);
    return 0;
    }

    OUTPUT:






    2

    3


    Logic:

    Constant Pointer:

    Syntax: datatype const *ptr
  • In case of a Constant Pointer , the value remains constant where the address can be varied.
  • In case you provide any modification in the value it will result in an error.

  • Pointer Constant:

    Syntax: datatype *const ptr
  • Incase of a Pointer Constant Address remains constant.
  • Pointer must be initialized (i.e., int *const p=&i)
  • If you modify the address, it will result in an error where as you can modify the value of the pointer.


  • NOTE:
    In const *p , *p points value so value is constant.
    In *const p, p points address so address is costant.

    But the following programs make error:




    int main()
    {
    int i=2;
    int const *p;
    p=&i;
    *p=3
    printf("%d",*p);
    return 0;
    }

    int main()
    {
    int i=2,j;
    int *const p=&i;
    p=&j;
    printf("%d",*p);
    return 0;
    }