How can i write comment in professional way to explain my code

The 2 usual ways is to write comments like this:

// This is a comment on only one row

/* This is comments on
2 rows or
more than 2 rows for example*/

How can i write comment in professional way to explain my code

/*enter comments here*/

i don't ask about comment syntax
but i ask about
what it shoud to write
and
where write it before or after the codes lines

and if there progams calculates the comment lines , the empty lines and the code lines in agroup of code files and calculate the code efficiecy

thanks alot

I am not sure what you meen but usually if you write a line of code it is best to write a comment on the same row as the code to the right will say if there is space.
However it doesn´t matter where in you code you have your comments for the compiler to be effectively. It just skipps over the comments. There is no priority.

If you write comment for example under a code. Tell in the code that you refer to the above code and do a hint to what you refer to.

Hope this helped !

>How can i write comment in professional way to explain my code
Copied from my reply to a similar question on cprogramming.com:

The way I explain commenting to my team is that any given piece of code causes you to ask one of three questions:

1) "What is it doing?"
2) "Why is it doing that?"
3) "How is it doing that?"

Code and comments work together to answer those questions.

Question 1 is always answered with a comment[1].

Question 2 is always answered with a comment. Code can't tell you why it's doing something.

Question 3 is always answered with code. The very definition of code is to outline the steps for solving a problem.

With that in mind, any comment that doesn't answer question 1 or 2 is a bad comment. Our code reviews take comments very seriously, and I often find myself following this line of conversation:

Me: "What's this doing?"
Coder: "It's doing <blah blah> for <blah blah> to <blah blah>."
Me: "Why did you have to tell me that?"
Coder: "Because it's badly commented?"
Me: "You got it in one."

[1] Transparent code also answers this question, but transparency is too subjective. So I just tell my team to treat question 1 as an "always comment". This saves the newbies from an experienced coder's ego, and it saves experienced coders from a newbie's bad judgement.

I've found that following the Javadoc and/or Doxygen type of thing aims me toward better comments.

What about

and if there progams calculates the comment lines , the empty lines and the code lines in agroup of code files and calculate the code efficiecy

thanks alot

//*************************************************************
//*************************************************************
// Program name
// Copyright (c) 200? by
// ALL RIGHTS RESERVED
//*************************************************************
//*************************************************************
// Date: Coded by:
// Filename: Module name:
// Source file:
// Program description:
//
//*************************************************************
// Libraries and software support:
//
//*************************************************************
// Development environment:
//
//*************************************************************
// System requirements:
//
//*************************************************************
// Start date:
// Update history:
// DATE MODIFICATION
//
//*************************************************************
// Test history:
// TEST PROTOCOL DATE TEST RESULTS
//
//*************************************************************
// Programmer comments:
//
//
//*************************************************************
//*************************************************************


try this one....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.