C Programming language

adplus-dvertising
What is printf

In this section we are going to Provide What is printf, What is scanf,Difference between Declaration and Definition, What is odd loop and Keywords in C with Examples.

Previous Home Next

What is printf

The printf statement allows you to send output on screen and see the output of that program. that is following given bellow.

Example


#include <stdio.h>
int main()
{
    int x, y, n;
    x = 2;
    y = 5;
    n = x + y;
    printf("%d + %d = %d\n", x, y, n);
    return 0;
}

output:


2 5 7

What is scanf

The scanf function allows you to accept input from users via keyboard. which for us is generally the keyboard.

The scanf function can do a lot of different things, but it is generally unreliable unless used in the simplest ways.

It is unreliable because it does not handle human errors very well. But for simple programs it is good enough and easy-to-use.

scanf("%d", &b):

The scanf function uses the same placeholders as printf


    int uses %d
    float uses %f
    char uses %c
    character strings  use %s

Example of the scanf


 #include <stdio.h>
 int main()
{
    int a, b, c;
    printf("Enter the first value:");
    scanf("%d", &a);
    printf("Enter the second value:");
    scanf("%d", &b);
    c = a + b;
    printf("%d + %d = %d\n", a, b, c);
    return 0;
}

output:


a=2 b=3 c=5

Difference between Declaration and Definition

declaration introduces just the name and type of something but allocates no storage, while definition, also allocates the space used by the thing being declared.

Example of Declaration and Definition


int func_dec(void);
 /*
* Because this function has a body, it is also a definition.
* Any variables declared inside will be definitions,
* unless the keyword 'extern' is used.
* Don't use 'extern' until you understand it!
*/
int def_func(void){
     float f_var;            /* a definition */
     int c;            /* another definition */
     int random_num(void);    /* declare (but not define) another function */
return(0);
}

What is odd loop?

Loop is the repetition of data according to the given conditions "so odd loop is that loop which only repeat the odd numbers & it leave the even numbes".

Example of odd loop:


main( )
{
char ritu = 'a' ;
int num ;
for ( ; ritu == 'a' ; )
{
printf ( "Enter a number " ) ;
scanf ( "%d", &num ) ;
printf ( "square of %d is %d", num, num * num ) ;
printf ( "nWant to enter another number y/n " ) ;
scanf ( " %c", &ritu ) ;
}
}

Keywords in c

Keywords are the words. The keywords cannot be used as variable names because if we do so we are trying to assign a new meaning to the keyword, which is not allowed by the computer. Some C compilers allow you to construct variable names that exactly resemble the keywords. However, it would be safer not to mix up the variable names and the keywords. The keywords are also called ‘Reserved words’.

There are only 32 keywords available in C. that is given given below:

auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while

Identifier in C

An identifier is nothing but a data type. It may variable, content, structure or a pointer.

Previous Home Next