Author: learnconline

Write a C program that reads in a lowercase character, converts it to uppercase and then displays the uppercase equivalent 3

Write a C program that reads in a lowercase character, converts it to uppercase and then displays the uppercase equivalent

C program that converts lowercase character to its uppercase equivalent and displays it Explanation Step 1: Read the lowercase character Step 2: Convert the lowercase character to its uppercase by using the library function toupper() Step 3: Display the converted uppercase character Note: The function toupper() used in this program is a library function which is generally included in the header file ctype.h and the purpose of this function is to convert the lowercase letter to its uppercase. #include<stdio.h> #include<ctype.h> void main() { char lower, upper; lower = getchar(); upper = toupper(lower); putchar(upper); } Output: l L

Write a program in C that reads a line of text into the computer and then writes back out in its original form 3

Write a program in C that reads a line of text into the computer and then writes back out in its original form

Below is the C program that reads a line of text into the computer and then writes back out in its original form Explanation Step 1: Read the line of text by using the library function gets() and store it in an array Step 2: Display the read line by using the library function puts() Program: #include<stdio.h> void main() { char line[80]; gets(line); puts(line); } Output: Learn C Online is the best tutorial website to learn C Learn C Online is the best tutorial website to learn C

Passing pointers to functions in C 1

Passing pointers to functions in C

Pointers in C are often passed to a function as arguments. This allows data items within the calling portion of the program to be accessed by the function, altered within the function, and then returned to the calling portion of the program in altered form. We call this use of pointers in functions as passing arguments by reference (or by address or by location), in contrast to passing arguments by value. When an argument is passed by value, the data item is copied to the function. Thus, any alteration made to the data item within the function is not carried...

Understanding the difference between pass by value and pass by reference in C 0

Understanding the difference between pass by value and pass by reference in C

Let us understand the difference between pass by value and pass by reference in C. Given below is a simple C program that illustrates the difference between ordinary arguments, which are passed by value, and pointer arguments, which are passed by reference. #include<stdio.h> void funct1(int a, int b); /*function prototype*/ void funct2(int *pa, int *pb); /*function prototype*/ void main() { int a = 1; int b = 3; printf(“\nBefore calling funct1: a=%d b=%d”, a, b); funct1(a, b); printf(“\nAfter calling funct1: a=%d b=%d”, a, b); printf(“\nBefore calling funct2: a=%d b=%d”, a, b); funct2(&a, &b); printf(“\nAfter calling funct2: a=%d b=%d”, a, b);...

Unions in C Programming Language 2

Unions in C Programming Language

Unions in C programming language (like structures) contains members whose individual data type may differ from one another. However, the members within a union all share the same storage area within the computer’s memory whereas each member within a structure is assigned its own unique storage area. Thus, unions in C are used to conserve memory. They are useful for applications involving multiple members, where values need not be assigned to all the members at any one time. Within a union in C, the bookkeeping required to store members whose data types are different (having different memory requirements) is handled...

Program in C that reads radius of a circle and calculates its area 1

Program in C that reads radius of a circle and calculates its area

The below program in C will accepts the radius of a circle from the user and calculates its area and displays the calculated result to the user on the screen. Explanation Step 1: Read the radius Step 2: Calculate the area by applying the formula: Area = (pi)*r2 = 3.14 * r2 #include<stdio.h> #include<conio.h> void main() { float radius, area; printf(“Radius = ?”); scanf(“%f”, &radius); //calculate the area area = 3.14 * radius * radius; //display the calculated result printf(“Area = %f”, area); getch(); } Output: Radius = ?5 Area = 78.500000

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet