Home | Add to Favorites | Ebooks Directory | News  
C ,C++  Programming
Home
C , C ++  Article
C and C++  Tutorial 
C++  compiler
C++  Books
C and C++ Questions
C ++ Coding
C++ Source Code
C Tutorial

The following Simple Hello World Program explains how to write a basic c program


 

Coding in C-An Illustration

/* Hello World program */
#include<stdio.h>
void main()
{
printf("hello world");
}

The first line /* Hello World program */ is a comment. Comments in C begin with /* and end with */
The second line #include<stdio.h> includes the stdio.h file which contains input-output functions to be performed by the C-compiler.
The void main() is the default function to be called first ,it is the entry point for the program.
The printf(...) function prints the message specified.It can take any no:of arguments


 

Sample Program 1

Concatenation of two strings

The string.h file contains the string related functions like strlen which finds the length of the given string argument

#include<stdio.h>
#include<string.h>
void main()
{
     char str1[80],str2[80];
     int i1,i2;
     printf("input the strings to be concatenated");
     gets(str1);
     gets(str2);
     i1=strlen(str1);
     i2=0;
     for(i1=strlen(str1),i2=0;str2[i2];i1++,i2++)
             str1[i1]=str2[i2];
     str1[i1]=0;
     printf(concatenated string is");
     puts(str1);
}     

Compile the programs and run it to see the results