Class 6 Exam  >  Class 6 Notes  >  C Programming for Beginners  >  C Syntax & Output

C Syntax & Output | C Programming for Beginners - Class 6 PDF Download

Syntax

You have already seen the following code a couple of times in the first chapters. Let's break it down to understand it better:

Example

#include <stdio.h>


int main() {

  printf("Hello World!");

  return 0;

}

Example explained

  • Line 1: #include <stdio.h> is a header file library that lets us work with input and output functions, such as printf() (used in line 4). Header files add functionality to C programs.

Don't worry if you don't understand how  #include <stdio.h> works. Just think of it as something that (almost) always appears in your program.

  • Line 2: A blank line. C ignores white space. But we use it to make the code more readable.
  • Line 3: Another thing that always appear in a C program, is main(). This is called a function. Any code inside its curly brackets {} will be executed.
  • Line 4: printf() is a function used to output/print text to the screen. In our example it will output "Hello World".

Note that: Every C statement ends with a semicolon ;

Note: The body of int main() could also been written as:

int main(){printf("Hello World!");return 0;}

Remember: The compiler ignores white spaces. However, multiple lines makes the code more readable.

  • Line 5: return 0 ends the main() function.
  • Line 6: Do not forget to add the closing curly bracket } to actually end the main function.

C Output

Output (Print Text)

The printf() function is used to output values/print text:

Example

#include <stdio.h>


int main() {

  printf("Hello World!");

  return 0;

}

You can add as many printf() functions as you want. However, note that it does not insert a new line at the end of the output:

Example

#include <stdio.h>


int main() {

  printf("Hello World!");

  printf("I am learning C.");

  return 0;

}

C New Lines

To insert a new line, you can use the \n character:

Example

#include <stdio.h>


int main() {

  printf("Hello World!\n");

  printf("I am learning C.");

  return 0;

}

You can also output multiple lines with a single printf() function. However, be aware that this will make the code harder to read:

Example

#include <stdio.h>


int main() {

  printf("Hello World!\nI am learning C.\nAnd it is awesome!");

  return 0;

}

Tip: Two \n characters after each other will create a blank line:

Example

#include <stdio.h>


int main() {

  printf("Hello World!\n\n");

  printf("I am learning C.");

  return 0;

}

The document C Syntax & Output | C Programming for Beginners - Class 6 is a part of the Class 6 Course C Programming for Beginners.
All you need of Class 6 at this link: Class 6
10 videos|13 docs|15 tests

Top Courses for Class 6

10 videos|13 docs|15 tests
Download as PDF
Explore Courses for Class 6 exam

Top Courses for Class 6

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

ppt

,

Sample Paper

,

Free

,

shortcuts and tricks

,

Exam

,

practice quizzes

,

Extra Questions

,

Important questions

,

Summary

,

past year papers

,

mock tests for examination

,

video lectures

,

pdf

,

C Syntax & Output | C Programming for Beginners - Class 6

,

C Syntax & Output | C Programming for Beginners - Class 6

,

MCQs

,

study material

,

Previous Year Questions with Solutions

,

Objective type Questions

,

Viva Questions

,

Semester Notes

,

C Syntax & Output | C Programming for Beginners - Class 6

;