7 Replies - 25251 Views - Last Post: 26 July 2011 - 10:05 AM Rate Topic: -----

#1 Mogan rangan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-July 11

Debugging questions for quiz program

Posted 25 July 2011 - 08:06 AM

I'm preparing debugging quiz program on c & c++ for my college symposium, plz give some of the questions and answers for me. It will be help full for me.

This post has been edited by Mogan rangan: 25 July 2011 - 08:08 AM

Is This A Good Question/Topic? 0
  • +

Replies To: Debugging questions for quiz program

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Debugging questions for quiz program

Posted 25 July 2011 - 08:17 AM

If you're setting a quiz then at least you should be able to complete it yourself! :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#3 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Debugging questions for quiz program

Posted 25 July 2011 - 08:20 AM

What? If you are looking for code to debug we have a whole forum full.

What exactly are you asking?
Was This Post Helpful? 0
  • +
  • -

#4 Mogan rangan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-July 11

Re: Debugging questions for quiz program

Posted 25 July 2011 - 08:34 PM

View PostNickDMax, on 25 July 2011 - 08:20 AM, said:

What? If you are looking for code to debug we have a whole forum full.

What exactly are you asking?


i'm preparing a debugging qiuz program.
for that i want some question as like below,

main()
{
int i;
clrscr();
printf("%d", &i)+1;
scanf("%d", i)-1;
}
a. Run time error. b. Run time error. Access violation.

c. Compile error. Illegal syntax d. None of the above


here the answer s option "d".

i want question with choices lik this in both c & c++ code.
plz plz help me, it ll be very help full for me... :)
Was This Post Helpful? 0
  • +
  • -

#5 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1770
  • View blog
  • Posts: 3,429
  • Joined: 30-May 10

Re: Debugging questions for quiz program

Posted 25 July 2011 - 11:07 PM

> here the answer s option "d".
Except if you're using a compiler such as gcc which checks printf/scanf format strings, the answer is 'c'.
Well it isn't a syntactic failure, but a semantic failure. Regardless, it isn't compiling.

Try to focus on the language, and not make the people taking the quiz "Oh, I have to guess which compiler the author was thinking of, let's guess TurboC".

I've seen plenty of these kinds of quizzes, and most of them are fatally flawed because they assume a particular compiler.

Here is the last draft version of C99 (meaning it is also free). The minor differences between that and a proper (not free) C99 standard would only interest compiler writer's.
http://std.dkuug.dk/.../www/docs/n869/

Ask your questions relating to the information in there.
Was This Post Helpful? 1
  • +
  • -

#6 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Debugging questions for quiz program

Posted 26 July 2011 - 08:53 AM

View PostMogan rangan, on 25 July 2011 - 11:34 PM, said:

View PostNickDMax, on 25 July 2011 - 08:20 AM, said:

What? If you are looking for code to debug we have a whole forum full.

What exactly are you asking?


i'm preparing a debugging qiuz program.
for that i want some question as like below,

main()
{
int i;
clrscr();
printf("%d", &i)+1;
scanf("%d", i)-1;
}
a. Run time error. b. Run time error. Access violation.

c. Compile error. Illegal syntax d. None of the above


here the answer s option "d".

i want question with choices lik this in both c & c++ code.
plz plz help me, it ll be very help full for me... :)


See when I look at that program I see:

#1 it does not include headers so it has no access to printf/scanf/clrscr -- syntax error(s)
#2 it does not use the standard definition for main: int main() or int main(int argc, char* argv[]) syntax error
#3 printf("%d", &i) is printing the address of i -- this maybe an error depending upon the intent of the programmer. Normally when we see this the thought was to print the VALUE of i, not its ADDRESS.

#4 The +1 at the end of the printf and scanf is not technically an error but it is unneeded and useless code that does not actually do anything since the result of the expression are not stored anywhere.

i.e. that is HORRIBLE programming and if the answer is "there is nothing wrong with this code" than your quiz program is just as horrible as that snippet.


I will say that your program should also give a summary of what the intent of the program is since many errors are not syntax errors but logic errors made by typos (such as &i when you wanted the value and not the address).
Was This Post Helpful? 1
  • +
  • -

#7 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Debugging questions for quiz program

Posted 26 July 2011 - 09:15 AM

I agree with NickDMax here, you need something that effectively doesn't amount undefined/incorrect code, but something that is obfucated. Here is an example:


bool GetAnswer()
{
   bool ans;

   // Do some action that requires user input.
   
   return ans;
}

...

   int i = 0;

   while(!GetAnswer(), ++i);




And get them to answer precisely what this program does. I haven't tested the code btw, but it should give you some idea of what I'm getting at.
Was This Post Helpful? 0
  • +
  • -

#8 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Debugging questions for quiz program

Posted 26 July 2011 - 10:05 AM

There may be some books that you could check out that might be of use.

C++ Gotchas: Avoiding Common Problems in Coding and Design -- lists a lot of common "gotchas" that often lead to errors.

How Not to Program in C++ this used to be a neat website but then it got published and the website went away. Its really a neat list of example bugs.

DO NOT copy/paste from these resources but use them as inspiration. They have some very good examples.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1