Escape Sequence \n vs multiple printf function calls - C Language Basics

C examples for Language Basics:printf

Introduction

The following code segment generates three separate lines with only one printf() function.

Demo Code

#include <stdio.h>

int main(){//from  ww  w .  j av a 2  s  .c o  m
    printf("line 1\nline2\nline3\n"); 
    return 0;
}

Result

The next code segment demonstrates how escape sequence \n can be used with multiple printf() statements to create a single line of output.

Demo Code

#include <stdio.h>

int main(){//from w w  w .  ja  va  2 s .  c  o  m

    printf("C "); 
    
    printf("from "); 
    
    printf("book2s.com \n"); 

    return 0;
}

Result


Related Tutorials