0% found this document useful (0 votes)
1 views14 pages

Advanced 2

Uploaded by

shitalmohod15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views14 pages

Advanced 2

Uploaded by

shitalmohod15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

#include<stdio.

h>
void main()
{

unsigned char c;

typedef struct name


{
long a;
int b;
long c;
}r;

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]);
}
*/

//here we are going to p[1]="pawan" where p[1][0] is p and we are trying to


increment but that string is store in read only section because of char pointer so
modifying data will generate segmenattion fault error

//ans:segmemtation fault error


///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
int const RCB[3]={0x10};
void main()
{
auto char *q=RCB[1];
printf("%d \n",++q);

*/

//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);
}

*/

//ans:here fisrt value of structure assign as address of structure pointer so


//ANS:10

///////////////////////////////////////////////////////////////
/*

#include<stdio.h>

int main()
{
short int *p;
p=(short int *)29;
++p;
p=p-5;
printf("%d \n", p);
}
*/

//ans:21 //INCREMENT DECREMENT BY 2(SHORT INT)

///////////////////////////////////////////////////////////////
/*
#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);

}
*/

//ans:2 //no break is there so it will execute all task

///////////////////////////////////////////////////////////////

/*
#include<stdio.h>
char* fun(char *);
main()
{
char *str = "C ARM 8051",*pky;
pky=fun(str);
printf("%s \n",pky);
}

char* fun(char *a)


{
int i=0;

while(*a)
{
i++;
a++;

if(i>=6)
break;
}
return a;
}

//ans:8051
*/

///////////////////////////////////////////////////////////////

/*
#include<stdio.h>
main()
{

struct xx
{
int x=3;
char name[]="hello";
};

struct xx *s=malloc(sizeof(struct xx));


printf("%d",s->x);
printf("%s",s->name);

//at time of declaration memory we can not assign


//ANS:ERROR

*/

///////////////////////////////////////////////////////////////

/*
#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

printf("%x \n", SRH->i);

}
*/

//ans:a61

///////////////////////////////////////////////////////////////
/*
#include<stdio.h>
main()
{

int k=120;
char *i = (char*)&k;

for(;*i>=0; ++*i);
printf("%d\n", *i);

*/

//ans:-128

///////////////////////////////////////////////////////////////

//Which keyword use to tell os to take data from memory only?

//ans:volatile

///////////////////////////////////////////////////////////////

/*
#include<stdio.h>
main()
{
int i=1,j=9;

if(i>=5 && j<5)

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);

printf("%d \n", c);

}
*/

//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};

struct bit *p=&v;

printf("%d %d %d\n",p->b,p->a,v.c);
return 0;

}
*/

//ANS:-19 -16 -31

///////////////////////////////////////////////////////////////

//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);

printf("%d\n",&v->cpp+21); //ERROR (PRIORITY AND


ASSOCIATIVITY)
printf("%d\n",*blr.cpp); //ERROR (PRIORITY AND
ASSOCIATIVITY)
return 0;
}
*/

//ANS:-35

///////////////////////////////////////////////////////////////

/*
main()
{
extern int i;
i=20;
printf("%d",sizeof(i));

}
*/

//ANS: L VALUE ERROR

///////////////////////////////////////////////////////////////

/*
enum {false,true};
main()
{
int i=1;

do
{
printf("%d",i);
i++;

if(i < 15)


continue;

}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;

typedef struct name


{
long a;
int b;
long c;
}r;

r re = {3,4,5}; r *na= &re;


printf("%d", *(int *) ((char *)na + (unsigned int) & ((((struct name *)0) ->
b));
}

*/

//ANS:ERROR

///////////////////////////////////////////////////////////////

//DOUBT

#define sum(a,b,c) a+b+c


#define avg(a,b,c) sum(a,b,c)/3
#define geq(a,b,c) avg(a,b,c) >= 60
#define lee(a,b,c) avg(a,b,c) <= 60
#define des(a,b,c,d) (d==1?geq(a,b,c):lee(a,b,c))
int main ()
{
int num = 70;
char ch = '0';
float f = 2.0;

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

printf("%d ",arr[1][2][0]); //14


printf("%d ",arr[0][3][1]); //11
printf("%d ",arr[1][2][4]); //garbage

*/

///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////

You might also like