Posts

Data Types in C

Data types are the type of data stored in a C program. Data types are used while defining a variable or functions in C. It’s important for the compiler to understand the type of predefined data it is going to encounter in the program. In this article, we will discuss Data type in C programming with example. What is Data Type in C? C provides several built-in data types, such as integer (int), character (char), floating-point (float), and double-precision floating-point (double), among others. Each data type has its own set of possible values and operations that can be performed on it. Example Of Data Types In C Let’s consider a scenario of a company. A company stores various data of their employee such as Name, Employee ID, Age, Salary, Address, Phone No, etc. Now, these data are values containing alphabets, numbers, etc, so to make the processing of these huge data for programs easy, the information was categorized into different types: Name: String ID: Integer Salary: Float or Double

How does do while loop works in C ?

Image
do…while Loop in C The do…while in C is a loop statement used to repeat some part of the code till the given condition is fulfilled. It is a form of an exit-controlled or post-tested loop where the test condition is checked after executing the body of the loop. Due to this, the statements in the do…while loop will always be executed at least once no matter what the condition is. Syntax of do…while Loop in C do { // body of do-while loop } while (condition); How does the do…while Loop works? Syntax Structure of do while loop The working of the do…while loop is explained below: When the program control first comes to the do…while loop, the body of the loop is executed first and then the test condition/expression is checked, unlike other loops where the test condition is checked first. Due to this property, the do…while loop is also called exit controlled or post-tested loop. When the test condition is evaluated as true, the program control goes to the start of the loop and the body is

How does a While Loop works in C ?

  All About While Loop in C In a programming language, loops are used to repeat a specific piece of code. Loops in C are classified into three types:  For loop , While loop, and Do while loop. In this article, we will explore the   While  loop in   C language . The while loop allows code to be executed iteratively until a given condition is true. We will learn how to implement while loop in C programs.  While Loop in C The while loop in C is used to evaluate a test condition and iterate over the loop body until the condition returns True. The loop ends when the condition returns False. This loop is also known as a pre-tested loop because it is commonly used when the number of iterations is unknown to the user ahead of time. While Loop Syntax in C Here’s the syntax for the while loop in C while (condition) {     // Code to execute as long as the condition is true } Here,  while:  This is the keyword that begins the while loop. condition:  This is a Boolean expression that is evaluated b

How does the "for loop" work in C?

  How does the "for loop" work? The for loop in C first evaluates the initialization expression. If it evaluates true, the first iteration of the loop will run, if false the loop will not run. The code within the loop will executed and then the loop will be updated by the loop expression and re-evaluated. If it is evaluated as true again, the body will run again. If it is false, the loop will exit. How do computer programmers write a "for loop"? The basic syntax of a  for loop in C  is the for statement followed by a number of control expressions separated by semi-colons: for (A;  B;  C) { body } A = initialize expression - the expression that will be used in the first evaluation B = conditional expression - the expression that will be used to evaluate whether the loop should run again or exit C = loop expression(increment/decrement) - this updates the variable for each iteration of the loop The body is the block of code that will run as long as the conditional ex

what is return 0 in c ?

What is the exact use of return 0 in c programming? When does the 0 goes to or returns to ? What is a calling function? Can some one explain me this with using simple language as I am not familiar with programming? The statement  return 0;  is used to indicate that a C program has completed successfully and is ready to exit. When you write a C program, the main function typically has the following structure: int main() {   // Your program code goes here   return 0;   }   The  return 0;  statement at the end of the  main()  function is used to indicate that the program has executed without any errors. The value  0  is then returned to the operating system or the program that called your C program. Inside the main function : return 0:  A return  0  means that the program will execute successfully and did what it was intended to do. return 1:  A return  1  means that there is some error while executing the program, and it is not performing what it was intended to do. Inside the us

main() function in C

What is main Function in C ? The main function is an integral part of the programming languages such as C, C++, and Java. The main function in C is the entry point of a program where the execution of a program starts.  It is a user-defined function that is mandatory for the execution of a program because when a C program is executed, the operating system starts executing the statements in the main() function. Syntax of C main() Function return_type  main()  {   // Statement 1 ;   // Statement 2 ;   // and so on..   return ;  } Types of C main Functions Main function with no arguments and void return type void main() { // Function body } Main function with no arguments and int return type int main() { // Function body } Main function with the Command Line Arguments int main(int argc, char* argv[]) { // Function body }

Declare an Array in C

-Declare an Array -Syntax of an Array -How to initialize an Array Arrays Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To create an array, define the data type (like  int ) and specify the name of the array followed by  square brackets [] . We can declare an array in the c language in the following way. data_type  array_name [array_size]; To insert values to it, use a comma-separated list, inside curly braces: Integer Data Type Array Declaration and Initialization: int  myNumbers[4] = {  25 ,  50 ,  75 ,  100  }; Float Data Type Array Declaration and Initialization: float myNumbers[4]  =  { 25.50,  50.20,  75.00,  100.60 } ; Char Data Type Array Declaration and Initialization: char myChar[4] = { 'c',  'h',   '$',  '*'  } ;