C Programming Codes
13.4K subscribers
139 photos
2 videos
12 links
C Programming Codes || Quizzes || DSA

Learn along with the community

Any queries
admin - @Pradeep_saii
Download Telegram
// performing subraction on pointers.
#include<stdio.h>
void main()
{
int a[5]={6,4,2,5,8};
int *p=&a[0];
int *q=&a[4];
printf("p-q=%d\n",p-q); //p-q=-4
*q=15; // now a[4]=15
printf("q-p=%d\n",q-p); //q-p=4
*p=32; //now ,a[0]=32
q=q-3; //now q is pointing to a[1]
printf("value:%d\n",*q); //value:4
p=p+3; //now p is pointing to a[3]
printf("value:%d\n",*p); //value:5
printf("p-q=%d\n",p-q); //p-q=2
}
👍2
//Performing increment and decrement on pointer
#include<stdio.h>
void main()
{
int a[5]={5,4,6,8,3};
int *p=&a[0];
printf("Value:%d\n",*p); // Value:5
p++; // now,p is pointing to a[1]
printf("Value:%d\n",*p); // Value:4
++p; // now p is pointing to a[2]
printf("Value:%d\n",*p); // value:6
p--; // now p is pointing to a[1]
printf("Value:%d\n",*p); // value:4
--p; // now p is pointing to a[0]
printf("Value:%d\n",*p); // Value:5
}
👍3
#include<stdio.h>
void main()
{
int a[7]={4,8,3,6,1,2,7};
int *p=&a[0],*q;
printf("%d\n",*p); //4
printf("%d,%d,%d\n",(*p)++,*p++,*++p); //3,8,8
printf("%d\n",*p); //4
q=p+3; //q is pointing to a[5]
printf("%d\n",*q-3); //-1
printf("%d\n",*--p+5); //13
printf("%d\n",*p+*q); //10
}
// void pointer- A void pointer is a special pointer type that can hold the
// address of any data type.
//dereferencing of void pointer can only be done after typecasting into other data type.
#include<stdio.h>
void main()
{ void *vp;
int a=10;
float b=5.5;
char ch='b';
vp=&a;
printf("%d\n",*(int*)vp);
vp=&b;
printf("%f\n",*(float*)vp);
vp=&ch;
printf("%c",*(char*)vp);
}
👍2
// NULL pointer-NULL pointer is a special value that represents a pointer
// that does not point to any valid memory address.
// dereferencing of a NULL pointer can't be done.
#include<stdio.h>
void main()
{ int *ptr=NULL;
if(ptr==NULL){
printf("ptr is a NULL pointer");
}
else{
printf("ptr is not a NULL pointer ");
}

}
👍3
Wild Pointer-A wild pointer refers to a pointer that is uninitialized or has been assigned an arbitrary value that does not point to a valid memory address
/* Performing sum of two numbers using ,
Function with no arguments and without return type.*/
#include<stdio.h>
void sum(void);
int main()
{
sum();
return 0;
}
void sum()
{
int a,b,sum=0;
a=4;
b=9;
sum=a+b;
printf("sum=%d",sum);
}
👍5
/* Performing sum of two numbers using ,
Function with no arguments and with return type.*/
#include<stdio.h>
int sum(void);
int main()
{ int res;
res=sum();
printf("Sum=%d",res);
return 0;
}
int sum()
{
int a,b,sum=0;
a=10;
b=45;
sum=a+b;
return sum;
}
👍3
/* Performing sum of two numbers using ,
Function with arguments and without return type.*/
#include<stdio.h>
void sum(int,int);
int main()
{ int a,b;
a=42;
b=32;
sum(a,b);
return 0;
}
void sum(int x,int y)
{
int sum=0;
sum=x+y;
printf("Sum=%d",sum);
}
👍3
/* Performing sum of two numbers using ,
Function with arguments and with return type.*/
#include<stdio.h>
int sum(int,int);
int main()
{ int a,b,res;
a=20;
b=5;
res=sum(a,b);
printf("Sum=%d",res);
return 0;
}
int sum(int x,int y)
{
int sum=0;
sum=x+y;
return sum;
}
👍9
//practice program 1
#include<stdio.h>
int main()
{
   int x=3,y=5,z=6;
   int a,b;
   a=x*2+y/5-z*y;
   b=++x*(y-3)/2-z++*y;
   printf("a=%d\nb=%d",a,b);
   return 0;
}

What is the value of a and b ?
leave comment 👇
👍5
//practice program 2
#include<stdio.h>
int main()
{
int a,b=4;
char c='A';
a=b+c;
printf("a=%d",a);
return 0;
}
//comment the output👇
👍5
//practice program 3
#include<stdio.h>
int main()
{
int a;
printf("%d\n",1/3+1/3);
printf("%f\n",1.0/3.0+1.0/3.0);
a=15/10.0+3/2;
printf("%d\n",a);
return 0;
}
// comment the output👇
👍2
//practice program 4
#include<stdio.h>
int main()
{ int a=4;
printf("%d\n",15+a++);
printf("%d",15+ ++a);
return 0;
}
//comment the output👇
👍2
//practice program 5
#include<stdio.h>
int main()
{ int a=4,b=5,c=9;
a=b==c;
printf("a=%d",a);
return 0;
}
//comment the output👇
👍3
//practice program 6
#include<stdio.h>
int main()
{ int a=1,b=2,c=3,d=4,e=5,res;
res=a+b/c-d*e;
printf("%d\n",res);
res=(a+b)/c-d*e;
printf("%d\n",res);
res=a+(b/(c-d))*e;
printf("%d\n",res);
return 0;
}
//comment the output👇
//practice program 7
#include<stdio.h>
int main()
{ int a=10,b=15;
printf("%d",(a>b)?a:b);
return 0;
}
//comment the output👇
👍4
//practice program 8
#include<stdio.h>
int main()
{ int a=4,b=12,c=-3,res;
res=a>b&&a<c;
printf("%d\n",res);
res=a==c||a<b;
printf("%d\n",res);
res=b>10||b&&c<0||a>0;
printf("%d\n",res);
res=(a/2.0==0.0&&b/2.0!=0.0)||c<0.0;
printf("%d\n",res);
return 0;
}
//comment the output👇
👍2
//practice program 9
#include<stdio.h>
int main()
{ int a=20,b=5,result;
float c=20.0,d=5.0;
printf("%d\n",10+a/4*b);
printf("%f\n",c/d*b+a-b);
return 0;
}
//comment the output👇
👍3🔥1
//practice program 10
#include<stdio.h>
int main()
{ int a=3;
a=!a;
printf("%d",a);
return 0;
}
//comment the output👇
4
#include<stdio.h>
int main()
{ int a=-2;
printf("%d",-a);
return 0;
}
👍2