PDA

View Full Version : C Programming theory



chaoprokia
April 7th, 2011, 12:16 PM
Thanks

simeon87
April 7th, 2011, 12:24 PM
What do you think the answers are to the given questions and why? This sounds like homework or exams questions.

chaoprokia
April 7th, 2011, 12:32 PM
What do you think the answers are to the given questions and why? This sounds like homework or exams questions.
Yeah part of my homework to discover the fact. which i am trying to understand how is it being derive. well if no one can help me i try other ways.

simeon87
April 7th, 2011, 12:41 PM
Yeah part of my homework to discover the fact. which i am trying to understand how is it being derive. well if no one can help me i try other ways.

My answers would be:

Q1: "Conditional compilation is provided by C compiler" is false because it is provided by the preprocessor, not the compiler.

Q2: The content of the struct is being printed but it's rather meaningless because you didn't initialize it. It's only a logic error if the printed content is important for the executing of the program (i.e., showing meaningful information to the user). Otherwise, it's not really a logic error as nobody really cares about the printed values.

chaoprokia
April 7th, 2011, 01:05 PM
My answers would be:

Q1: "Conditional compilation is provided by C compiler" is false because it is provided by the preprocessor, not the compiler.

Q2: The content of the struct is being printed but it's rather meaningless because you didn't initialize it. It's only a logic error if the printed content is important for the executing of the program (i.e., showing meaningful information to the user). Otherwise, it's not really a logic error as nobody really cares about the printed values.

Q2.let say my Struct has 2 value Student Name and Student ID. The Program main functionally is to print Student Name and Student ID.
But i declare it and didn't initialize it and print it. so this is an logic error. It is not an logic error if the struct doesn't do stuff?

simeon87
April 7th, 2011, 01:23 PM
Q2.let say my Struct has 2 value Student Name and Student ID. The Program main functionally is to print Student Name and Student ID.
But i declare it and didn't initialize it and print it. so this is an logic error. It is not an logic error if the struct doesn't do stuff?

What is or is not a logic error isn't rigidly defined. I'm just saying that I personally don't think it's a logic error when the printed value plays no meaningful role in the program. But if the main purpose is to show a student name and ID and it would print a meaningless value then it's indeed a logic error.

MadCow108
April 7th, 2011, 01:28 PM
Q2.let say my Struct has 2 value Student Name and Student ID. The Program main functionally is to print Student Name and Student ID.
But i declare it and didn't initialize it and print it. so this is an logic error. It is not an logic error if the struct doesn't do stuff?

if the point of the program is to print nonsensical garbage (or zeros depending on where the struct is allocated), then no its no logic error.
In any other case yes.

chaoprokia
April 7th, 2011, 02:08 PM
What is or is not a logic error isn't rigidly defined. I'm just saying that I personally don't think it's a logic error when the printed value plays no meaningful role in the program. But if the main purpose is to show a student name and ID and it would print a meaningless value then it's indeed a logic error.


if the point of the program is to print nonsensical garbage (or zeros depending on where the struct is allocated), then no its no logic error.
In any other case yes.

ok thanks i understand more clearly on what is an logic error and what not.