Advanced 2
Advanced 2
h>
void main()
{
unsigned char c;
r re = {3,4,5};
r *na= &re;
printf("%d", *(int *) ((char *)na + (unsigned int) & (((struct name *)0) -> b))) ;
}
//ans : 4
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
void main()
{
static char *s[] = {"black", "white", "yellow", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf("%s",*--*++p + 3);
}
//ans:ck
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
typedef int sirji;
typedef char coding;
void main()
{
sirji i=502;
coding *p=&i;
printf("%d\n",*p);
//ans=-10
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
extern int k;
void main()
{
short int *p=&k;
printf("%x\n",*++p);
}
//int k=0x12abcdef; //if you don't provide value to k and try to access
adress of k main then at that time memory not assign but after
writing some value outside of value in k its ok
//ans:12ab
*/
///////////////////////////////////////////////////////////////
/*
#include<stdlib.h>
#include<stdio.h>
static int a[]={11,22,33};
typedef struct st
{
int n;
}DLL;
int main()
{
DLL *head=NULL;
head=calloc(1,4);
head->n=*a+2;
printf("%d \n",head->n);
}
*/
//ans=13
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
char *p[5]={"c","pawan","ds"};
int main()
{
printf("%c\n",++p[1][0]);
}
*/
*/
//ans:1
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
typedef struct Node{
struct Node *prev;
int RCB;
struct Node *next;
}CDLL;
CDLL v={&v,'2',&v};
int main()
{
CDLL *head=&v;
printf("%d \n",head->prev->RCB);
}
*/
//ans:50
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int main()
{
union u
{
int i;
char c:4;
}v={02345};
union u *RCB=&v;
printf("%d \n",v.c);
}
*/
//ans=5
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
struct st
{
int x;
int y;
};
main()
{
struct st *p={10,20};
printf("%d %d\n",p->x,p->y);
}
*/
//ans: here p is poniter so pointer hold address if we assign any one value no
problem as pointer address but we are assighning multiple value and after that we
are derefrencing that pointer so it will run perfectly but whenever we will run our
code we will get segmentation fault error
//RUNTIME ERROR (SEGMENTATION FAULT)
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
struct st
{
int x;
int y;
};
main()
{
struct st *p={10,20};
printf("%d",p->x);
}
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int main()
{
short int *p;
p=(short int *)29;
++p;
p=p-5;
printf("%d \n", p);
}
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
char* rev(void);
void main()
{
extern char dec[];
printf ("%c",*rev());
}
char* rev(void)
{
char dec[]="abcde";
return dec;
}
*/
//ans:local arry so when function end variable value life will end and that type
of variable we are trying to derefrence so (ste)
//SEGMENTATION FAULT ERROR
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
char k=22;
int vector(void)
{
k=11;
}
int main()
{
//vector(); //condition-2
printf("%d \n",k);
}
*/
//CONDITION-1:our program execution goes to main and we if we will not call that
function then no change will ocuur to global value main part will execute
//ANS:22
//CONDITION-2:if we will call vector function in main then that part will execute
it will modify global value in global location so nmow that will affect in entire
program so now //ANS:11
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int vector(void)
{
return 4,5,6; //coma operator act as operator so right
most value it will return
}
int main()
{
printf("%x \n", vector()+'0');
}
*/
//ans:36
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
main()
{
int x = 5;
int y = 2;
char op = '*';
switch (op)
{
default: x += 1;
case '+': x += y;
case '-': x=y;
//default: x += 1; //chek this also comment first
default condition
}
printf("%d\n",x);
}
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
char* fun(char *);
main()
{
char *str = "C ARM 8051",*pky;
pky=fun(str);
printf("%s \n",pky);
}
while(*a)
{
i++;
a++;
if(i>=6)
break;
}
return a;
}
//ans:8051
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
*/
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int main()
{
union u
{
int i;
char c;
}v={0xabc};
union u *SRH=&v;
v.c='a'; //this char wiil store 97 in 1st
byte
}
*/
//ans:a61
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
main()
{
int k=120;
char *i = (char*)&k;
for(;*i>=0; ++*i);
printf("%d\n", *i);
*/
//ans:-128
///////////////////////////////////////////////////////////////
//ans:volatile
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
main()
{
int i=1,j=9;
i=j+2;
printf("%d\n",i);
}
*/
//after if we have puted space but still next line i=j+2 consider as if body and
here if condition false
//ANS:1
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int main()
{
char guru= A;
printf("%d \n",guru);
}
*/
//ans:error
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int main()
{
static int k=0xa;
if(--k>7)
{
main();
printf("%d \n",k);
}
return 0;
}
*/
//ANS: 7 7
//static reinitialization will not happend and updated value will assign(here no
stackframe concept static value store in code section)
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
typedef struct Node
{
struct Node *prev;
int rn;
struct Node *next;
}DLL;
DLL v={NULL,33,NULL};
int main()
{
DLL *head=&v;
printf("%d \n",head->prev);
}
*/
//ANS:0
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
const static int *p=NULL;
int main()
{
auto int z=11;
int **q=(int **)&p;
q=&z;
printf("%d \n",**q);
return 0;
}
*/
//ANS:STE(segmenattion fault)
//double pointer holding variable address and we are derefrencing two times
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
main()
{
func(1);
}
func (int i)
{
static char *str[] = { "One", "Two", "Three", "Four" };
printf ("%s ", str[i++]);
return;
}
*/
//ANS:two
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
#define CSK(i,j) i/2*j
int main()
{
int a=11,b=5,c;
const int *p=&b;
c=CSK(a,*p);
}
*/
//ANS:25
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
enum IPL{CSK, RCB, SRH,MI};
int main()
{
enum IPL k;
k= MI+RCB;
printf("%d \n", k);
return 0;
}
*/
//ANS:4
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
void vector(void)
{
printf("india \n");
}
int main()
{
printf("%d \n", vector());
}
*/
//ANS:ERROR
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int main()
{
struct bit
{
int a:5;
int b:6;
int c:7;
}v={16,45,97};
printf("%d %d %d\n",p->b,p->a,v.c);
return 0;
}
*/
///////////////////////////////////////////////////////////////
//Which keyword is used to come out of a loop only for that iteration?
//ans=continue
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
#define s32 int
typedef char s8;
struct vector
{
s32 c;
s8 cpp;
}v={100,200};
int main()
{
struct vector *blr=&v;
//printf("%d \n",blr->cpp+21);
//printf("%d\n",(&v)->cpp+21);
//printf("%d\n",(*blr).cpp+21);
//ANS:-35
///////////////////////////////////////////////////////////////
/*
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
*/
///////////////////////////////////////////////////////////////
/*
enum {false,true};
main()
{
int i=1;
do
{
printf("%d",i);
i++;
}while(false);
}
*/
//ANS: 1
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
typedef struct Node
{
struct Node *prev;
int rn;
struct Node *next;
}DLL;
DLL v={NULL,0x21,NULL};
int main()
{
DLL *head=&v;
printf("%x\n",v.rn<<4);
}
*/
///////////////////////////////////////////////////////////////
//DOUBT
/*
main()
{
unsigned char c;
*/
//ANS:ERROR
///////////////////////////////////////////////////////////////
//DOUBT
if des(num,ch,f,0)
puts("lee..");
else
puts("geq...");
//ANS:geq...
///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
void main()
{
int arr[2][3][3]={{{2,4},{3,4},{7,4},},{{10,11},{12,13},{14,15},}};
printf("%d\n",**(arr+1)+2+7); //garbage
*/
///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////