Search This Blog

Tuesday, July 5, 2022

C Program Comments| C Comments

 C Program Comments| C Programming Comments

C Comments can be single lined or multi lined.

Comments make the program more readable and explains the program in a better way.

Single lined comments start with two slashes (//) , and the compiler ignores those lines i.e. will not be executed by the compiler.

Example of single lined comment:

#include <stdio.h>

int main()

{

//This is a comment.

printf("Hello World!");

return 0;

}

OUTPUT of above program:

Hello World!



Multi lined comment starts with /* and ends with */

so as soon as the compiler comes across /* it starts ignoring those lines from compiling and as soon it comes across */ compiler understands end of comment.


Example of multi lined comments:

int main()

{

/*This is a comment.*/

printf("Hello World!");

return 0;

}

OUTPUT:

Hello World!

C Program for Escape sequence \" | Programming with C language

Programming with C language| C Program with escape sequence \" 

\":: Inserts double quote character.

#include <stdio.h>

int main() {

  printf("My name is \"Johnny\".");

  return 0;

}


OUTPUT of the above Program:

My name is "Johnny".

Sunday, July 3, 2022

C Program | C Programming using Escape Sequence \n \t \\ \"

 C Program | C Programming using escape sequence

-->\n    goes to new line

-->\t     creates a horizontal tab 

EXAMPLE FOR HORIZONTAL TAB

#include <stdio.h>

int main() {

  printf("Hello World!\t");

  printf("I am learning C.");

  return 0;

}

OUTPUT:

Hello World!        I am learning C.


\\     Inserts a backslash character (\)

\"     Inserts a double quote character (")

C Program | C Programming | printf() function to write multiple lines using new line \n.

C Program| C Programming| C Language | Basics of C| C new lines


How to use printf() function to write multiple lines using \n, however it makes the code difficult to read.


#include<stdio.h>

int main() {

  printf("Hello World! \n I am learning C.\n Its Great learning C!");
  return 0;
}

Output will be:

Hello World!
I am learning C.
Its Great learning C!

Second way to write C program using new line.

#include <stdio.h>

int main() {
  printf("Hello World!\n\n");
  printf("I am learning C.");
  return 0;
}

Output:

Hello World!


I am Learning C.