C

How to check the value of variable in C programming?

Value of Variable in C: The following source code is written in C Programming language. It mainly consists of four sections. First section imports standard input-output library.

Section 2 is a void function which returns nothing but prints ‘=’ sign on the screen as per loop’s instruction. This loop starts from 1 and repeats until value becomes equal to 35. In each iteration, loop increments 1 in value of i. If I modify i++ to i+2 or i+3, it will add 2 or 3 respectively each time in previous value of i.

Section 3 is also a void function which returns nothing but prints new line with \n and my name.

Section 4 is main function where we make call to above created functions to render via function call line(); and header();.

int a initializes a variable of integer type. printf shows message to user and scanf waits for user to give some input. if is conditional statement which checks either user has entered value 7 or not.I have used != (not operator) to check, so it will be true, input value will not be 7 and vice versa. I have given source code below, you may copy it and run in your computer. If you find any issue, you may leave comment.

//section 1
#include<stdio.h>

//section 2
void line()
{
int i;
    printf("\n");
for(i=1;i<=35;i++)
    printf("=");
}
//section 3
void header()
{
printf("\n");
printf(" Coded by Arslan ud Din Shafiq");
printf("\n           www.imarslan.com");
printf("\n");
}
//section 4
int main()
{
line();
header();
line();

int a;
printf("\nEnter a Number : ");
scanf("%d",&a);
if (a!=7)
    printf("\nThe variable is not equal to 7.");
else printf("You have entered variable 7.\n");
return 0;
}
Arslan ud Din Shafiq

Alibaba Cloud MVP, Alibaba Cloud Technical Author, Dzone MVB, Software Engineer, Software Developer, Software Designer, Web Engineer, Web Developer, Web Designer, Database Designer, Database Developer, Cloud Computing Specialist, Linux Expert, Servers, 3D Modeling, Blogger, Facebook Map Editor, Google Map Editor

Share
Published by
Arslan ud Din Shafiq

Recent Posts

How To Set Up Secure Nginx Server Blocks on Ubuntu 22.04

NGINX Server Nginx, a popular open-source web server, excels at handling high traffic websites efficiently.… Read More

5 hours ago

The Web Server Showdown: Nginx vs. Apache, LiteSpeed, Caddy, and Beyond

In the realm of web hosting, choosing the right web server is paramount. It acts… Read More

5 hours ago

Linear guidance systems

Are indispensable for ensuring smooth, precise linear motion in many industrial applications. Whether in robotics,… Read More

2 months ago

Cyber Attack Statistics – Identifying Vulnerabilities and Strengthening Defenses

Cyber attacks are becoming more frequent, complex, and damaging. They can disrupt critical operations and… Read More

3 months ago

Empowering Cybersecurity in 2024 with XDR for Comprehensive Threat Detection and Response

With the rise of new threats and the increasing complexity of IT environments, organizations need… Read More

3 months ago

Facade Design Pattern: Simplifying Complex Systems

1. Introduction In software design, managing complex systems can be challenging. The Facade Design Pattern… Read More

4 months ago