Wednesday, 27 August 2014

Bug Snipers


Code Snipers(Preliminary Round)- Questions
Copy and Paste the debugged  answers in the Google form.
For queries contact the event co-ordinators!

Find the Ridiculous Bugs and have headshot on it!

Happie DeBugging.... 
All the Best!!!
Click here to get the Answer sheets!

//Functions

1)
void main()
  {
        m();
        void m()
        {
            printf("hi");
        }
  }

//pointers

2)
#include<stdio.h>
int main()
{
    int *x;
    *x=100;
    return 0;
}

3)

#include<stdio.h>
int main()
{
    int a[] = {10, 20, 30, 40, 50};
    int j;
    for(j=0; j<5; j++)
    {
        printf("%d\n", a);
        a++;
    }
    return 0;
}

//Structure and unions

4)
struct emp
{
    int ecode;
    struct emp *e;
};

5)

typedef struct data mystruct;
struct data
{
    int x;
    mystruct *b;
};

6)

#include<stdio.h>
int main()
{
    struct a
    {
        float category:5;
        char scheme:4;
    };
    printf("size=%d", sizeof(struct a));
    return 0;
}

7)

struct emp
{
    int ecode;
    struct emp e;
};

8)

#include<stdio.h>
int main()
{
    struct emp
    {
        char name[25];
        int age;
        float bs;
    };
    struct emp e;
    e.name = "Suresh";
    e.age = 25;
    printf("%s %d\n", e.name, e.age);
    return 0;
}

9)

#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
    char name[20];
    int age;
};
int main()
{
    struct emp e = {"Sanjay", 35};
    modify(&e);
    printf("%s %d", e.name, e.age);
    return 0;
}
void modify(struct emp *p)
{
     p ->age=p->age+2;
}

10)

#include<stdio.h>
int main()
{
    struct bits
    {
        int i:40;
    }bit;

    printf("%d\n", sizeof(bit));

    return 0;
}

//Array

11)
#include<stdio.h>
void fun(int *p[][4]);
int main()
{
    int a[3][4];
    fun(a);
    return 0;
}

12)

#include<stdio.h>
int main()
{
    int size, i;
    scanf("%d", &size);
    int arr[size];
    for(i=1; i<=size; i++)
    {
        scanf("%d", arr[i]);
        printf("%d", arr[i]);
    }
    return 0;
}

What is the output of the following(13-17)

13)
#include<stdio.h>
#include<string.h>
int main()
{
    char str1[20] = "Hello", str2[20] = " World";
    printf("%s\n", strcpy(str2, strcat(str1, str2)));
    return 0;
}

14)

#include<stdio.h>
int main()
{
    char p[] = "%d\n";
    p[1] = 'c';
    printf(p, 65);
    return 0;
}

15)

#include<stdio.h>
#include<string.h>
int main()
{
    printf("%d\n", strlen("123456"));
    return 0;
}

16)

#include<stdio.h>
int main()
{
    printf(5+"Good Morning\n");
    return 0;
}

17)

#include<stdio.h>
#include<string.h>
int main()
{
    char str[] = "tce\0\cse\0";
    printf("%s\n", str);
    return 0;
}

//Constructors and Destructors

18)
#include<iostream.h>
class CSE
{
    int x;
    public:
    CSE(int xx, float yy)
    {
        cout<< char(int(y)y);
    }
};
int main()
{
    CSE *p = new CSE(35, 99.50f);
    return 0;
}

19)

#include<iostream.h>
class cse
{
      int x;
    public:
      cse();
      cse();
      void const Show() ;
};
cse:cse()
{
    x = 25;
}
void cse:Show() const
{
    cout<< x;
}
int main()
{
    cse objB;
    objB.Show();
    return 0;
}

20)To ensure that every object in the array receives a destructor call,

always delete memory allocated as an array with operator __________ .

//object and class

21)
#include<iostream.h>
class cse
{
    public:
      int x;
};
int main()
{
    cse *p = new cse();

    (*p).x = 10;

    cout<< (*p).x << " " << p.x << " " ;

    p->x = 20;

    cout<< (*p).x << " " << p.x ;

    return 0;

}

22)

#include<iostream.h>
class cse
{
    static int x;
    public:
    static void SetData(int xx)
    {
        x = xx;
    }
    void Display()
    {
        cout<< x ;
    }
};
int cse::x = 0;
int main()
{
    cse::SetData(33);
    cse::Display();
    return 0;
}

23)

#include<iostream.h>
class cse
{
    static int x;
    public:
    static void SetData(int xx)
    {
        x = xx;
    }
    static void Display()
    {
        cout<< x ;
    }
};
int cse::x = 0;
int main()
{
    cse::SetData(44);
    cse::Display();
    return 0;
}

//References

24)
#include<iostream.h>
int main()
{
    int x = 80;
    int y& = x;
    x++;
    cout << x << " " << --y;
    return 0;
}

25)

#include<iostream.h>
int main()
{
    int x;
    int &y = x;
    x++;
    cout << x << " " << --y;
    return 0;
}

26)

#include<iostream.h>
int main()
{
    int *x = 10;
    int *y = &x;
    x++;
    cout<< x << " " << y++;
    return 0;
}

27)

#include<iostream.h>
int main()
{
    int x = 10;
    int y = x;
    x = 25;
    y = 50;
    cout<< x << " " << --y;
    return 0;
}

//Memory Allocation

28)
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int *a[3];
    a = (int*) malloc(sizeof(int)*3);
    free(a);
    return 0;
}

29)

#include<stdio.h>
#include<stdlib.h>

int main()

{
    char *ptr;
    *ptr = (char)malloc(30);
    strcpy(ptr, "RAM");
    printf("%s", ptr);
    free(ptr);
    return 0;
}

//bonus question

30)
#include <iostream>
int main()
{
  int h;
  cout>>hy;
  cin<<h;
  return char(h);
}