Welcome to our website

Here we Provide C, C++, Java, Oracle and More Tutorials for online searchings for Tutorials.
  • Fully Responsive

    • We Response with in 24 hours regarding any doubts in our Tutorials

C Variables and Types of Variables in C

C variable is a data name that may be used to store a data value. The value of the C variable may get change in the program and it can be reused many times.
syntax to declare a variable:
type variable name = value;

Example of C variables:

int i = 1, j = 2;               // Declaration and initializing i and j.
float f = 10.53;              //Declaration and initializing f.


Rules for defining variables:

  • C variable can have alphabets, digits, and underscore and must begin with a letter.
  • C variable name can start with the alphabet, and underscore only can have both upper and lower case letters. It can't start with a digit.
  • No whitespace is allowed within the variable name.
  • C variable name must not be any reserved word (or) keyword, e.g. int, float, char, etc.

Types of Variables in C: The types of variables in c are shown below:
  • The local variable.
  • Global variable.
  • The static variable.
  • Automatic variable.
  • External variable.

Local Variable: A variable that is declared inside the function or block is called a local variable. The local variable must be declared at the start of the block. And local variable must have to initialize before it is used.

Example of C Local variable:

void functionA()
{  
int i=10; // "i" is the local variable.
}  
Global Variable: Any variable that is declared outside the function or block is called a global variable. A global variable must be declared at the start of the function (or) block and it is available to all the functions. Any function can change the value of the global variable.

Example of C Global variable:

int i = 20;    // Here "i" is the global variable  
void function1()
{  
 int j =10;    //Here "j" is the local variable  
}  

Static variable: The static variable has a property of preserving their value even after they are out of their scope. Hence, static variables preserve their previous value in their previous scope and are not initialized again in the new scope.
Syntax:
static datatype varname = varvalue; 

Automatic variable: The variables which are declared inside a block are known as automatic these variables allocate memory automatically upon entry to that block and free the occupied memory upon exit from that block. These variables have local scope to that block only which means these can be accessed in which variable declared. Keyword 'auto' may be used to declare an automatic variable but we can declare these variables without using 'auto' keywords.
 Example: Below Both x, y are automatic variables
  int main()
    {
    auto int x;
    int y;
    ....
    return 0;
    }
External variables: External variables are also known as global variables. These variables are defined outside the function. These variables are available globally throughout the function execution. The value of global variables can be modified by the functions. “extern” keyword is used to declare and define the external variables. About the declaration shown below:
  • Declaration of a variable or function simply declares that the variable or function exists somewhere in the program, but the memory is not allocated for them. The declaration of a variable or function serves an important role–it tells the program what its type is going to be. In the case of function declarations, it also tells the program the arguments, their data types, the order of those arguments, and the return type of the function. So that’s all about the declaration.
  • Coming to the definition, when we define a variable or function, in addition to everything that a declaration does, it also allocates memory for that variable or function. Therefore, we can think of definition as a superset of the declaration (or declaration as a subset of definition).
Example:
#include <stdio.h>
extern int i = 24;
int j = 8;
int main() {
   auto int a = 32;
   extern int j;
   printf("The value of auto variable : %d\n", a);
   printf("The value of extern variables i and j : %d,%d\n",i,j);
   x = 15;
   printf("The value of modified extern variable i : %d\n",i);
   return 0;
}
Share:

SEO and Important of SEO

What is SEO?

SEO stands for Search Engine Optimization. It is the process of getting traffic from the free, organic, editorial, or natural search results on the search engines. And SEO is the process of improving the structure, content, and organization of your site to the Search engines can index them correctly. SEO may target different kinds of search, including image search, local search, video search, and news search engines.
what is seo

Important points to Note:

  • You ought to be mindful so as to remember the accompanying focuses so as to guarantee your image is all around situated on web indexes.
  • Web crawlers need to carry out their responsibilities as most ideal as by alluding clients to sites and substance that is generally important to what the client is searching for. This is dictated by the website content, how quick your webpage loads, how regularly your website is connected to from other dependable online assets, and client experience, including structure, route and skip rate. 
  • The things that the web crawlers don't need are: watchword stuffing, purchasing connections, and poor client experience (such a large number of promotions and high skip rates). 
  • Area naming is critical to your general marking. As a best practice, use sub-registry root areas (example.com/occasions) versus sub-spaces (events.example.com). Other accepted procedures with area names are to utilize steady spaces and watchwords in the URL. 
  • Upgrade for various kinds of results. Notwithstanding improving for work area experience, center around portable and tablet enhancement alongside other media. 
  • Content on the site ought to have title labels and meta depictions. Despite the fact that meta labels aren't as significant as they used to be previously; in the event that you do utilize them, guarantee they are organized effectively.
Also See: Java strings interview questions Java collections interview questions Java exception handling interview questions Java multithreading interview questions Java io streams interview questions Core Java interview questions Java constructor interview questions USPS Tracking USPS Hold Mail   Liteblue Liteblue login Earthlink Webmail  RCN Webmail BU Webmail Towson University Webmail Gmail login Shaw Webmail Cox Email GoDaddy Webmail Walmart Credit Card Login TCS Webmail bookzz 192.168.0.1 liteblue usps gov human resources Hotmail login WalmartOne Login upsers outlook webmail Factorial program in Java constructor in java switch case in java java data types java if else Gmail sign in Gmail Gmail sign up AOL Mail login PSU Webmail Juno Webmail Rackspace Webmail Webmail DQFanSurvey Tellpopeyes survey Kroger feedback Disney hub tiktok login Netflix login

Share:

C Data Types and Types of data types in C

Data types specify the type of data that a variable can store. All C compilers support Five fundamental data types, they are an integer(int), character(char), floating-point(float), double-precision floating-point(double) and void.

There are the following data types in C language.


TypesData Types
Primary Data Typeint, char, float, double
Derived Data Typearray, pointer, structure, union
Enumeration Data Typeenum
Void Data Typevoid

Following are the examples of some very commonly used data types used in C:

int: int variable is used to store an integer.
char: char stores a single character and requires a single byte of memory in almost all compilers.
float: It is used to store decimal numbers (numbers with floating-point value) with single precision.
double: It is used to store decimal numbers (numbers with floating-point value) with double precision.

Let's see the Primary data types. Its size is given according to 32-bit shown below:

Data TypesMemory SizeRange
char1 byte(8 bits)−128 to 127
signed char1 byte(8 bits)−128 to 127
unsigned char1 byte(8 bits)0 to 255
short2 byte(16 bits)−32,768 to 32,767
signed short2 byte(16 bits)−32,768 to 32,767
unsigned short2 byte(16 bits)0 to 65,535
int2 byte(16 bits)−32,768 to 32,767
signed int2 byte(16 bits)−32,768 to 32,767
unsigned int2 byte(16 bits)0 to 65,535
short int2 byte(16 bits)−32,768 to 32,767
signed short int2 byte(16 bits)−32,768 to 32,767
unsigned short int2 byte(16 bits)0 to 65,535
long int4 byte(32 bits)-2,147,483,648 to 2,147,483,647
signed long int4 byte(32 bits)-2,147,483,648 to 2,147,483,647
unsigned long int4 byte(32 bits)0 to 4,294,967,295
float4 byte(32 bits)
double8 byte(64 bits)
long double10 byte(80 bits)


C Data types Programs:
C Data types program:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
int main(int argc, char** argv) {
    printf("Character Bits:   %d\n", CHAR_BIT);
    printf("Character MAX :   %d\n", CHAR_MAX);
    printf("Character MIN :   %d\n", CHAR_MIN);
    printf("Integer MAX   :   %d\n", INT_MAX);
    printf("Integer MIN   :   %d\n", INT_MIN);
    printf("LONG MAX      :   %ld\n", (long) LONG_MAX);
    printf("LONG MIN      :   %ld\n", (long) LONG_MIN);
    printf("SCHAR_MAX     :   %d\n", SCHAR_MAX);
    printf("SCHAR_MIN     :   %d\n", SCHAR_MIN);
    printf("SHRT_MAX      :   %d\n", SHRT_MAX);
    printf("SHRT_MIN      :   %d\n", SHRT_MIN);
    printf("UCHAR_MAX     :   %d\n", UCHAR_MAX);
    printf("UINT_MAX      :   %u\n", (unsigned int) UINT_MAX);
    printf("ULONG_MAX     :   %lu\n", (unsigned long) ULONG_MAX);
    printf("USHRT_MAX     :   %d\n", (unsigned short) USHRT_MAX);
    return 0;
}

Output
Character Bits:   8                                                                                                                    
Character MAX :   127                                                                                                                  
Character MIN :   -128                                                                                                                 
Integer MAX   :   2147483647                                                                                                         
Integer MIN   :   -2147483648                                                                                                          
LONG MAX      :   9223372036854775807                                                                                    
LONG MIN      :   -9223372036854775808                                                                                    
SCHAR_MAX     :   127                                                                                                                  
SCHAR_MIN     :   -128                                                                                                                 
SHRT_MAX      :   32767                                                                                                                
SHRT_MIN      :   -32768                                                                                                               
UCHAR_MAX     :   255                                                                                                                  
UINT_MAX      :   4294967295                                                                                                       
ULONG_MAX     :   18446744073709551615                                                                                
USHRT_MAX     :   65535 
See Also C topics below:
Share:

Loops in C and Types of Loops in C

Loops in C:

In C, loops are used to execute a set of statements repeatedly until the given condition is satisfied.


flow chart diagram of loops



In loops sequence of statements to be executed inside the curly braces (“{}”) is known as the loop body. Every execution of the loop body condition is checked and if the condition is true loop body executes again. When condition checked to be False then loop body will not to be executed and come out of the loop and execute the remaining part of the program.

Types of the Loops in C language: 

There are three types of loops in C language. They are:
1) while loop.
2) do-while loop.
3) for loop.

Read: C For loop

While loop: While is a conditional control statement and it repeats a statement (or) block while its controlling is True. 

Syntax of While loop:


While Loop syntax:

while(condition)
{
  //body of the loop (statements)//

}
Flow chart diagram of C while loop

Explanation of the above diagram: In the while loop, the first condition is checked. If the condition is True, the code inside the body (means inside the parenthesis) will be executed. Again the loop executes until the condition becomes False when the condition becomes false exists from while loop.

Example of while program:

C While loop program:
#include<stdio.h>
 void main()
 {
  int i = 1;
    while( i < 5)
    {
     printf("i = %d\n",i);
     i++;
    }
 }


Output:
i = 1
i = 2
i = 3
i = 4
Explanation:
1) The first variable of type integer is declared and initialized to “1”.
2) While the loop condition is checked ( 1 < 5) condition is true. So the value of “i” is printed.
3) Then the value is incremented (i++) it becomes i = 2. If we did not use any increment (or) decrement operator then while loop will be executed continuously with a value i = 1. So we used the increment operator to satisfy the condition. 
4) The cycle continues until “i” becomes “5”. When “i” becomes “5” condition becomes fails. Control jumps out of the while loop.

Do-while: The do-while loop first executes the body of the loop and then the condition statement executes. If the expression is true, the loop repeat or else the loop terminates. There is a semicolon at the end of while() in do.

Syntax of Do - while loop:

C Do- While loop Syntax:
do
{
  //body of the loop//
}
while(condition);


Example of Do-while program:

C Do- While loop program:
#include<stdio.h>
 void main()
 { 
  int i = 1;
    do
    {
     printf("i = %d\n",i);
     i++;
    }
   while( i < 5);
 }
Output:
i = 1
i = 2
i = 3
i = 4
Share:

Switch Statement in C with Programs and Examples

Switch statement in C: If several options are available then it isn’t recommended to take nested if-else we should go for switch statement so that readability of the code will be improved. “Switch” is a keyword, by using which we can create a selection statement with multiple choices. Multiple choices can be constructed by using a “Case” keyword.

Syntax:

Switch Syntax:
Switch(expression)
{
 case exp1:
 statements;
 break;
 case exp2:
 statements;
 break;
 …………….
 …………….
 …………….
 case expression:
 statements;
 break;
 default:
 statements;
}
Explanation: In the above syntax, switch, case, break are keywords. Expr1, expr2 is known as “case labels”. Statements inside case expression need not be closed in braces. The break statement causes an exit from the switch statement.

The following rules apply to a switch statement:

1) The expression used in a switch statement must have an integral or enumerated type.
2) You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.
3) The constant-expression for a case must be the same data type as the variable in the switch, and it must be a constant or a literal.
4) When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.
5) When a break statement is reached, the switch terminates, and the flow of control jumps to the next line following the switch statement.
6) Not every case needs to contain a break. If no break appears, the flow of control will fall through to subsequent cases until a break is reached.
7) A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.

Switch statement in C Program 1 :

C Switch program Example:
#include<stdio.h>
void main()
{
 int number;
printf("Enter a number");
 scanf("%d",&number);
 switch(number)
 {
  case 1:
  printf("Welcome to TutorialWeb.org");
  break;
  case 2:
  printf("I am Java programmer");
  break;
  case 3:
  printf("Java programming in TutorialWeb.org");
  break;
  default:
  printf("Switch Program Example");
  break;
 }
}
Output:
Enter a number
1
Welcome to TutorialWeb.org

Explanation:

1) The integer value “1” is assigned to a number variable.
2) After switch case decides then 1st case block of code gets executed.
3) Switch case executes code from top to bottom. It will validate case number with the variable number.
4) If no match is found then it will jump to the next case. It checks until found if case is not found, then the default will be executed.

Switch statement in C Program 2 :

C Switch program Example:
#include<stdio.h>
void main()
{
 int number;
printf("Enter a number");
 scanf("%d",&number);
 switch(number)
 {
  case 1:
  printf("January");
  break;
  case 2:
  printf("February");
  break;
  case 3:
  printf("March");
  break;
  case 4:
  printf("April");
  break;
  case 5:
  printf("May");
  break;
  case 6:
  printf("June");
  break;
  case 7:
  printf("July");
  break;
  case 8:
  printf("August");
  break;
  case 9:
 printf("September");
  break;
  case 10:
  printf("October");
  break;
  case 11:
 printf("November");
  break;
  case 12:
  printf("December");
  break;
  default:
  printf("Enter number between 1 to 12");
  break;
 }
}
Output:
Enter a number
7
July
Read Also C Loops:


·     C if Else Statement
·     C For loop
Share:

Our Services

Search This Blog

  • ()
Powered by Blogger.

C Variables and Types of Variables in C

C variable is a data name that may be used to store a data value. The value of the C variable may get change in the program and it can be r...