-
-
-
strcpy(obj->pAddress, "Your Address");
free(obj);
printf("%s", obj->pName);
printf("%s", obj->pAddress);
}
">Struct Foo{ char *pName; char *pAddress;};main(){ struct Foo *obj = malloc(sizeof(struct Foo));clrscr(); obj->pName = malloc(100); obj->pAddress = malloc(100); strcpy(obj->pName,"Your Name"); strcpy(obj->pAddress, "Your Address"); free(obj); printf("%s", obj->pName); printf("%s", obj->pAddress);}
A) Your Name Your NameB) Your Address, Your AddressC) Your Name, Your AddressD) None of the aboveExplanation: Prints Nothing, as after free(obj), no memory is there containing obj->pName & pbj->pAddress
-
char *b = "World";
clrscr();
printf("%s", strcpy(a,b));
}
">Main(){ char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcpy(a,b));}
A) None of the aboveB) �HelloWorld�C) �Hello World�D) �Hello�Explanation: World, copies World on a, overwrites Hello in a.
-
}
">Main(){ int i = 100; clrscr(); printf("%d", sizeof(sizeof(i)));}
A) none of the aboveB) 4C) 100D) 2
-
}
}
">Main(){ int x=5; for(;x!=0;x--) { printf("x=%dn", x--); }}
A) 5, 3, 1B) 4, 3, 2, 1, 0C) 5, 4, 3, 2,1D) none of the aboveExplanation: Infinite loop as x is decremented twice, it never be 0 and loop is going on & on
-
}
}
">Main(){ int x=5; clrscr(); for(;x
A) 5, 3, 1, -1, 3B) 5, 2, 1C) 5, 3, 1D) None of the aboveExplanation: prints nothing, as condition in loop is false.
-
> (i - (i -1))));
}
}
">Main(){ signed int bit=512, i=5; for(;i;i--) { printf("%dn", bit = (bit >> (i - (i -1)))); }}
A) 128, 64, 32, 16, 8B) 256, 128, 64, 32, 16C) 512, 256, 128, 64, 32D) 64, 32, 16, 8, 4
-
}
else
{
printf("OK I am gone.");
}
}
">Main(){ if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); }}
A) none of the aboveB) compile errorC) OK I am goneD) OK I am done
-
-
-
-
-
-
-
C program for command line argument
Write c program to accepts file name at command line argument and coverts all characters in the file to uppercase ?
-
-
Output of these programs.
c
struct Foo
{
char *pName;
};
main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
}
a. Your Name
b. compile error
c. Name
d. Runtime error
c
struct Foo
{
char *pName;
char *pAddress;
}; -
-
C Interview Questions
Ans