Enhance your debugging skills!

Reya

Reya

@reya-SMihdC Oct 8, 2024
Hi CEans

If you think that you are good at debugging then why dont you try some of the debugging questions posted below.Post your output along with the correct code.The one who answers for more number of questions will get a prize from me.I will post more questions as soon as i get the answers for these questions.

1.Please dont use thanks,good,bad etc.Use "like" button if you think that it is good.
2.Dont use sms language.
3.The one who gives correct answer with the executable code will be taken first.
4.Please enclose your program using code tag.

1.what is the output??
#include<stdio.h>
#include<conio.h>
int main()
{
   char name[]="paradigm";
   fprintf(stdin,"hi");
   scanf("%s",name);
   printf("%s",name);
   getch();
   return 0;
}
2.2.Consider a database 'employees' containing the attributes name,dept_id,salary.. Which of the following subqueries will work?
A) Select * from employees where salary>(select min(salary) from employees group by dept_id));
B) Select * from employees where salary=(select avg(salary) from employees group by dept_id));
C) Select distinct dept_id from employees where salary> any (Select avg(salary) from employees group by dept_id)
D) Select dept_id from employees where salary>all(Select avg(salary) from employees group by dept_id));
E) select name from employees where salary>any(select max(salary) from employees group by dept_id));
F) Select dept_id from employees where salary>all(Select avg(salary) from employees group by avg(salary))
3.what is the output?
#include<stdio.h>
#include <setjmp.h>
jmp_buf buf;
#include <setjmp.h>
banana() {
printf("3 ");
longjmp(buf, 1);
printf("4 ");
}
main()
{
if (setjmp(buf))
printf("1 ");
else {
printf("2 ");
banana();
}
}
4.what is the output??
#include<stdio.h>
main ()
{
char *table[] = {“jan”,”feb”,”march”};
char **ptr = &table [1];
printf (“%c”, (*++*--ptr));
}
5.what is the output??
#include<stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    int a=20;
    printf("%d,%d",sizeof(++a),++a);
    getch();
    return 0;
}

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • silverscorpion

    silverscorpion

    @silverscorpion-iJKtdQ Mar 17, 2011

    1) hi
    4) f
    5) 2 21 (considering int to be 2 bytes long)
  • Reya

    Reya

    @reya-SMihdC Mar 17, 2011

    @Ram: Didn't you read what i have posted above the questions?
  • silverscorpion

    silverscorpion

    @silverscorpion-iJKtdQ Mar 17, 2011

    praveena211
    @Ram: Didn't you read what i have posted above the questions?
    Well, the question was what was the output. So, I just gave the output.. Anyway, here you go..

    1.
    #include<stdio.h>
    #include<conio.h>
    int main()
    {
       char name[]="paradigm";
       fprintf(stdin,"hi");
       scanf("%s",name);
       printf("%s",name);
       getch();
       return 0;
    }
    OUTPUT : "hi"


    4
    #include<stdio.h>
    main ()
    {
    char *table[] = {“jan”,”feb”,”march”};
    char **ptr = &table [1];
    printf (“%c”, (*++*--ptr));
    }
    OUTPUT : f


    5
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    int main()
    {
        int a=20;
        printf("%d,%d",sizeof(++a),++a);
        getch();
        return 0;
    }
    OUTPUT : 2 20
  • slashfear

    slashfear

    @slashfear-tSWzpz Mar 23, 2011

    Hi Praveena,

    Finally got time to solve these questions, so here are my answers 😀


    1) I guess the use of fprintf is not required, since it is used for file operations and it takes the 1st parameter as a pointer to a file and then the 2nd parameter as string format. So I have commented the fprintf and now the program should output like following:

    wait for the user input , once the user enter his name the value is overwriten the array named name (from paradigm to what ever name the user enters) and print the name.

    #include<stdio.h>
    #include<conio.h>
    int main()
    {        
       char name[]="paradigm";
      //fprintf(stdin,"hi");
       scanf("%s",name);
       printf("%s",name);
       getch();
       return 0;
    }
    
    2) The below querys will work fine

    A) Select * from employees where salary>(select min(salary) from employees group by dept_id));
    C) Select distinct dept_id from employees where salary> any (Select avg(salary) from employees group by dept_id)
    D) Select dept_id from employees where salary>all(Select avg(salary) from employees group by dept_id));
    E) select name from employees where salary>any(select max(salary) from employees group by dept_id));

    The reason why,

    B) Select * from employees where salary=(select avg(salary) from employees group by dept_id));

    wont work is because the inner most query will return multiple result set and will throw an error.

    The reason why,

    F) Select dept_id from employees where salary>all(Select avg(salary) from employees group by avg(salary))

    wont work is because we cannt use avg function in the group by clause.

    NOTE:And also in query C and F, I guess you have forgotten the ; at the end of the query by mistake.


    3) The output of the program will be 2 3 1 according to the code you have given the only prob is that there are two include files (#include<setjmp.h>). But the actual way I used setjmp is like follows and the program will output 1 2 3

    #include<stdio.h>
    #include <setjmp.h>
    jmp_buf buf;
             
    banana() {
    printf("2 "); 
    longjmp(buf, 1);
    printf("4 "); 
    }            
    main()
    {
    int i;
    i = setjmp(buf);
    if (i==0)
    {   
    printf("1 ");
    banana();
    }   
    else { 
    printf("3 ");
    }   
    }
    
    5) The program will output 4,21 since the sizeof operator will return the size of the variable a which is integer ( I am using linux gcc complier so the size of int is 4) and the value of a will be 21 as the increment operator in the size of will not work as size of operator is a complie time operator which just returns the size of the type and it does not require the value of a so increment will not take effect!! and the initial value of a (20) will be increment as you have used ++a and printed, as it is postfixing (since the value is increment and then used when you use postfixing)

    So according to me the ++a in the sizeof operator should be replaced with a, as it is of no use even if you increment it within sizeof!!
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>
    int main()
    {         
        int a=20; 
        printf("%d,%d",sizeof(a),++a);
        getch();
        return 0;
    } 
    
    
    -Arvind