main() {
extern int i;
Printf(“%d”,i);
}
int i = 20;
#include <stdio.h>
int calculate_fact(int);
int main()
{
int n=5,f;
f=calculate_fact(n); // calling a function
printf("factorial of a number is %d",f);
return 0;
}
int calculate_fact(int a)
{
if(a==1)
{
return 1;
}
else
return a*calculate_fact(a-1); //calling a function recursively.
}
factorial of a number is 120
int a[10]; ​
#define
, we can compile and run a C program without using the main()
function. For example:#include<stdio.h>
#define start main
void start() {
printf("Hello");
}
main()
function while executing the program is known as command line argument. main(int count, char *args[]){
//code to be executed
}
153 = (1*1*1)+(5*5*5)+(3*3*3)
where:
(1*1*1)=1
(5*5*5)=125
(3*3*3)=27
So:
1+125+27=153 ​
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
return 0;
}
enter the number=153
armstrong number
enter the number=5
not armstrong number
When x=4, x++ returns 5 and x- returns 3.​
When x=4, use x+1 to get 5 and x-1 to get 3.​
abs()
is for integer values and fabs()
is for floating type numbers. Prototype for abs()
is under the library file < stdlib.h >
and fabs()
is under < math.h >
. ++a
" is called prefixed increment and the increment will happen first on a variable. "a++
"is called postfix increment and the increment happens after the value of a variable used for the operations. while(0)
means that the looping conditions will always be false, i.e., the code inside the while loop will not be executed. On the opposite, while(1)
is an infinite loop. It runs continuously until coming across a break statement mentioned explicitly.while(-22)
and while(24)
will both yield an infinite loop.int a = 25;
size
) inside a structure. The general syntax of a bit
field is :struct {
type [member_name] : width ;
};
compilers
and kernels
. C language is as old as the hills, and most of the modern languages are nothing but an adaptation from the C languages. random
access file helps in solving this problem.FIFO
. The full form of FIFO
is first-in-first-out. In every queue, the first data is available on the first line. #include <stdio.h>
int main()
{
if(printf(“Hello World”))
{
/* Do nothing */
}
}
strcpy( )
function copies whole content of one string into another string. Whereas, strncpy( )
function copies portion of contents of one string into another string.atexit()
function more than once. But, they will be executed in reverse order as a stack.#include <stdio.h>
#include <stdlib.h>
void Exit1 (void)
{
printf ("Exit1 function is called\n");
}
void Exit2 (void)
{
printf ("Exit2 function is called \n");
}
int main (void)
{
atexit (Exit1);
atexit (Exit2);
printf ("This is the end of this program.\n");
return 0;
}
{
…….
goto label;
…….
…….
LABEL:
statements;
}
#include <file>
calloc()
, malloc()
, realloc()
and free()
. #include <stdio.h>
int main()
{
int x, y;
printf(“Input two integers (x & y) to swap\n”);
scanf(“%d%d”, &x, &y);
x = x + y;
y = x – y;
x = x – y;
printf(“x = %d\ny = %d\n”,x,y);
return 0;
}
(pointer_name)->(variable_name)
#include <stdio.h>
main() {
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;
printf(“Value of mean : %f\n”, mean );
}
bubble
” to the top of the list, while the larger value sinks to the bottom. [Height of the left subtree – Height of right subtree] <= 1
. <>
is incorrect. While this operator is correctly interpreted as "not equal to
" in writing conditional statements, it is not the proper operator to be used in C programming. Instead, the operator !=
must be used to indicate "not equal to
" condition. #
symbol. \n
character. This is used to insert a new line when displaying data in the output screen. More spaces can be added by inserting more \n
characters. For example, \n\n
would insert two spaces. A newline escape sequence can be placed before the actual output expression or after. Toupper()
function prototype is declared in <ctype.h>
. Note that this function will only convert a single character, and not an entire string. tic-tac-toe
program. If (num>=0)
printf("number is positive");
else
printf ("number is negative");