- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1401 Articles for C
3K+ Views
Pointers and arraysContinuous memory locations are allocated for all the elements of the array by the compiler.The base address is the location of the first element in the array.For example, int a [5] = {10, 20, 30, 40, 50};The five elements are stored as follows −If ‘p’ is declared as integer pointer, then the array ‘a’ can be pointed by the following assignment −p=a or p=&a[0];Each value of ‘a’ is accessed by using p++ to move from one element to another. When a pointer is incremented, its value is increased by the size of the datatype that it points to. ... Read More
1K+ Views
Pointer is a variable which stores the address of other variable.Pointer declaration, initialization and accessingConsider the following statement −int qty = 179;Declaring a pointerint *p;‘p’ is a pointer variable that holds the address of another integer variable.Initialization of a pointerAddress operator (&) is used to initialize a pointer variable.int qty = 175; int *p; p= &qty;Arithmetic operations using pointersPointer variables can be used in expressions. For example, if pointer variables are properly declared and initialized then the following statements are valid.a) *p1 + *p2 b) *p1- *p2 c) *p1 * *p2 d) *p1/ *p2 Note: There must be a blank ... Read More
2K+ Views
If individual elements are to be passed as arguments, then array elements along with their subscripts must be given in function call.To receive the elements, simple variables are used in function definition.Example 1#include main (){ void display (int, int); int a[5], i; clrscr(); printf (“enter 5 elements”); for (i=0; i
910 Views
ArrayThe array is a group of related items that store with a common name. Following are the two ways of passing arrays as arguments to functions −sending entire array as argument to functionsending individual elements as argument to functionSending entire array as an argument to a functionTo send entire array as argument, just send the array name in the function call.To receive an array, it must be declared in the function header.Example 1#include main (){ void display (int a[5]); int a[5], i; clrscr(); printf ("enter 5 elements"); for (i=0; i
384 Views
Local scopeLocal scope specifies that variables defined within the block are visible only in that block and invisible outside the block.Global scopeGlobal scope specifies that variables defined outside the block are visible up to end of the program.Example#include int r= 50; /* global area */ main (){ int p = 30; printf (“p=%d, r=%d” p, r); fun (); } fun (){ printf (“r=%d”, r); }Outputp =30, r = 50 r = 50Scope rules related to functionsA Function is a block of statements that performs a particular task.Variables that are declared within the body of a function ... Read More
249 Views
Global scopeGlobal scope specifies that variables defined outside the block are visible up to end of the program.Example#include int c= 30; /* global area */ main (){ int a = 10; printf (“a=%d, c=%d” a, c); fun (); } fun (){ printf (“c=%d”, c); }Outputa =10, c = 30 c = 30Local scopeLocal scope specifies that variables defined within the block are visible only in that block and invisible outside the block.Variables declared in a block or function (local) are accessible within that block and does not exist outside it.Example#include main (){ int i = ... Read More
25K+ Views
Depending on whether arguments are present or not and whether a value is returned or not, functions are categorized into − Functions without arguments and without return values Functions without arguments and with return values Functions with arguments and without return values Functions with arguments and with return values Functions without arguments and without return values Example ... Read More
13K+ Views
Functions are broadly classified into two types which are as follows −predefined functionsuser defined functionsPredefined (or) library functionsThese functions are already defined in the system libraries.Programmer can reuse the existing code in the system libraries which is helpful to write error free code.User must be aware of syntax of the function.For instance, sqrt() function is available in math.h library and its usage is y= sqrt (x), where x= number must be positive.If x value is 25, i.e., y = sqrt (25) then ‘y’ = 5.In the same way, printf() is available in stdio.h library and clrscr() is available in conio.h ... Read More
111K+ Views
ProblemApplying the software development method to solve any problem in C Language.SolutionFind roots of a quadratic equation, ax2+bx+c.There will be 2 roots for given quadratic equation.AnalysisInput − a, b, c valuesOutput − r1, r2 valuesProcedure$r_{1}=\frac{-b+\sqrt{b^2-4ac}}{2a}$$r_{2}=\frac{-b-\sqrt{b^2-4ac}}{2a}$Design (Algorithm)StartRead a, b, c valuesCompute d = b2 4acif d > 0 thenr1 = b+ sqrt (d)/(2*a)r2 = b sqrt(d)/(2*a)Otherwise if d = 0 thencompute r1 = -b/2a, r2=-b/2aprint r1, r2 valuesOtherwise if d < 0 then print roots are imaginaryStopImplementation Code# include # include int main () { float a, b, c, r1, r2, d; ... Read More
1K+ Views
An array of characters is called a string.DeclarationFollowing is the declaration for an array −char stringname [size];For example − char a[50]; string of length 50 charactersInitializationUsing single character constant −char a[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}Using string constants −char a[10] = "Hello":;AccessingThere is a control string "%s" used for accessing the string till it encounters ‘\0’.The logic used to convert vowels from upper to lower or lower to upper is −for(i=0;string[i]!='\0';i++){ if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){ string[i]=toupper(string[i]); } } printf("The result string with converted vowels is : "); puts(string);ProgramFollowing is the C program using conversion functions ... Read More