Вы находитесь на странице: 1из 28

Data Structure Assignment I

Instructions
1. Make a proper assignment copy
2. Submit assignment within 2 weeks (Exactly Friday, 23rd August 2019)
3. Submit in hardcopy
4. Write both question and answer with proper format. Code must follow proper indentation with comments.
5. While writing output take care of all the spaces and newlines properly.
6. All incorrect answers need to be resubmitted with the next assignment. If not done, then the next assignment will not
be checked.

Write output of the code segment with reason. [Some questions have other instructions. Follow the instructions for that
question only]

1. #include<stdio.h>
int main(){
int a = 2, b = 2, c = 0, d = 2, m;
m = a++ && b++ && c++ || d++;
printf("%d %d %d %d %d",a, b, c, d, m);
return 0;
}

2. #include<stdio.h>
int main(){
int i = 5;
if(i == 3, 4)
printf("Hai");
else
printf("No Hai");
return 0;
}

3. #include<stdio.h>
int main(){
int a = 5;
a = 1, 2, 3;
printf("%d", a);
return 0;
}

4. #include<stdio.h>
int main(){
int a;
a = (1, 2, 3);
printf("%d", a);
return 0;
}

5. #include<stdio.h>
int main(){
switch(25){
case 25L:
printf("25L");
break;
case 25.0:
printf("25.0");
break;
default:
printf("Nothing");
break;
}
return 0;
}

6. #include<stdio.h>
int main(){
char str[] = "\0";
if(printf("%s",str))
printf("inside if block");
else
printf("inside else block");
return 0;
}

7.#include<stdio.h>
int main(){
int i = 5, j = 4;
if(!printf(""))
printf("%d %d", i, j);
else
printf("%d %d", i++, ++j);
return 0;
}

8. #include<stdio.h>
int main(){
if(sizeof('\0'))
printf("inside if block");
else
printf("inside else block");
return 0;
}

9. #include<stdio.h>
int main(){
char str[8] = "hello";
char str1[8] = "2hello";
if(str == str1)
printf("Strings are Equal");
else
printf("Not Equal");
return 0;
}

10. #include<stdio.h>
int main(){
char *str = {"2braces"};
char *str1 = {"2braces"};
if(*str == *str1)
printf("inside if block");
else
printf("inside else block");
return 0;
}

11. C program to print "NITS", "Silchar" . Use both if and else statement

12.#include<stdio.h>
int main(){
char str1[] = "zoho";
char str2[] = "zoho";
if(strcmp(str1, str2))
printf("Strings are not same");
else
printf("Strings are Same");
return 0;
}

13. #include<stdio.h>
int main(){
char temp;
char arr[10] = {1, 2, 3, 4, 5, 6, 9, 8};
temp = (arr + 1)[2];
printf("%d\n", temp);
return 0;
}

14.#include<stdio.h>
int main(){
int _ = 5;
int __=5;
int ___ = _ + __;
printf("%d",___);
return 0;
}

15. #include<stdio.h>
int main(){
int arr[1] = {2};
printf("%d", 0[arr]);
return 0;
}

16. #include<stdio.h>
int main(){
char *ptr = "helloworld";
printf(ptr + 4);
return 0;
}
17. #include<stdio.h>
int main(){
int arr[3], i = 0;
while(i < 3) {
arr[i] = ++i;
}
for(i=0; i<3; i++){
printf("%d--", arr[i]);
}
return 0;
}

18. #include<stdio.h>
int main(){
printf("%d",EOF);
return 0;
}

19. #include<stdio.h>
int main(){
char *ptr = "2braces.com";
printf("%c\n",*&*ptr);
return 0;
}

20. #include<stdio.h>
int main(){
int scanf = 13;
printf("%d",scanf);
int printf = 13;
int c = 7 + printf;
printf("%d",c);
return 0;
}

21. #include<stdio.h>
int main(){
int a[][] = {{1,2},{3,4}};
int i, j;
for (i = 0; i < 2; i++)
for (j = 0; j < 2; j++)
printf("%d ", a[i][j]);
return 0;
}

22.#include<stdio.h>
int main(){
int a, b, c;
char *p = 0;
int *q = 0;
double *r = 0;
a = (int)(p + 1);
b = (int)(q + 1);
c = (int)(r + 1);
printf("%d %d %d",a, b, c);
return 0;
}

23. #include <stdio.h>


void main(){
int x=22;
if(x=10)
printf("TRUE");
else
printf("FALSE");
}

24. #include <stdio.h>


void main(){
char val=1;
if(val--==0)
printf("TRUE");
else
printf("FALSE");
}

25. #include<stdio.h>
int main(){
int main = 47;
printf("%d",main);
return 0;
}

26. #include<stdio.h>
int main(){
extern num;
printf("%d",num);
return 0;
}
int num = 36;

27. #include <stdio.h>


void main(){
float a=10.5;
printf("\n===FIRST CONDITION\n");
if(sizeof(a)==sizeof(10.5))
printf("Matched !!!");
else
printf("Not matched !!!");
}
28. #include <stdio.h>
void main(){
float a=10.5;
printf("\n===SECOND CONDITION\n");
if(sizeof(a)==sizeof(10.5f))
printf("Matched !!!");
else
printf("Not matched !!!");
}

29. #include <stdio.h>


void main(){
float a=10.5;
printf("\n===THIRD CONDITION\n");
if(sizeof((double)a)==sizeof(10.5))
printf("Matched !!!");
else
printf("Not matched !!!");
}

30. #include <stdio.h>


void main(){
float a=10.5;
printf("\n===FOURTH CONDITION\n");
if(a==10.5f)
printf("Matched !!!");
else
printf("Not matched !!!");
printf("\n");
}

31. #include<stdio.h>
int main(){
printf("%d", sizeof(void *));
return 0;
}
32. #include<stdio.h>
int main(){
char arr[] = "Cat";
*arr = 'B';
printf("%s", arr);
return 0;
}

33. Which of the following are incorrect statements? int a=10 is a statement.
a) if( 10==a ) printf("IncludeHelp");
c) if( 10=a ) printf("IncludeHelp");

34. #include<stdio.h>
#define i 10
int main(){
#define i 20
printf("%d",i);
return 0;
}

35 #include<stdio.h>
void main(){
int x=1;
if(x--)
printf("The Godfather");
--x;
else
printf("%d",x);
}

36 #include<stdio.h>
#define clrscr() 50
int main(){
clrscr();
printf("%d\n",clrscr());
return 0;
}

37. #include<stdio.h>
int main(){
struct node {
int a, b, c;
};
struct node num = {3, 5, 6};
struct node *ptr = & num;
printf("%d\n", *((int*)ptr + 1 + (3-2)));
return 0;
}
38 #include<stdio.h>
#define CONDITION(i)
printf("preprocessor\n");
int main(){
CONDITION(0);
return 0;
}

39. #include<stdio.h>
void main(){
if('\0');
else if(NULL)
printf("cquestionbank");
Else;
}

40. #include <stdio.h>


void main() {
int i=-1,j=-1,k=0,l=2,m;
m = i++ && j++ && k++ || l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}

41. #include<stdio.h>
int main(){
char array[5] = "Knot", *ptr, i, *ptr1;
ptr = &array[1];
ptr1 = ptr + 3;
*ptr1 = 101;
for(i = 0; i < 4;i++)
printf("%c", *ptr++);
return 0;
}

42. #include <stdio.h>


void main(){
int i=5;
printf("%d",i+++++i);
}

43. #include<stdio.h>
# define loop while(true)
int main(){
loop;
printf("preprocessor-aptitude");
return 0;
}
44. #include<stdio.h>
main(){
int a=2;
if(a-- , --a, a)
printf("Tom");
else
printf("Jerry");
}

45. #include<stdio.h>
#include<stdlib.h>
int main(){
int i, numbers[1];
numbers[0] = 9;
free(numbers);
printf("\nStored integers are ");
printf("\nnumbers[%d] = %d ", 0, numbers[0]);
return 0;
}

46. #include <stdio.h>


int main(){
int Y=10;
if( Y++ && Y++!=10 && Y++){
printf("%d", Y);
}
else {
printf("%d", Y);
}
return 0;
}

47. #include<stdio.h>
int main(){
int EOF = 0;
printf("%d", EOF);
return 0;
}
48. #include <stdio.h>
int main(){
int i=i++,j=j++,k=k++;
printf("%d%d%d",i,j,k);
return 0;
}

49.#include<stdio.h>
# define x --5
int main(){
printf("%d",x);
return 0;
}

50. #include <stdio.h>


int main(){
int a = 1, b = 1, d = 1;
printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);
}

51. #include<stdio.h>
int main(){
int i = 0, j = 1, k = 0;
if(++k, j, i++)
printf("%d %d %d", i, j, k);
return 0;
}

52. #include<stdio.h>
int main(){
int i;
if(true)
printf("This will work");
else
printf("This will not work");
return 0;
}

53. int main(){


printf("function");
main();
return 0;
}
54. #include<stdio.h>
int main(){
int i = 5, j = 5;
if(i == j);
printf("Equal");
else
printf("Not Equal");
return 0;
}

55. #include<stdio.h>
x() {
printf("Function");
}
y(){
printf("Function in C");
}
z(){
printf("C function");
}
main(){
int (*ptr[3])();
ptr[0] = x;
ptr[1] = y;
ptr[2] = z;
ptr[2]();
return 0;
}

56. #include<stdio.h>
int main(){
float me = 5.25;
double you = 5.25;
if(me == you)
printf("I love U");
else
break;
return 0;
}

57. void fun(int*, int*);


int main(){
int i=5, j=2;
fun(&i, &j);
printf("%d, %d", i, j);
return 0;
}
void fun(int *i, int *j){
*i = *i**i;*j = *j**j;
}

58. int fun(int(*)());


int main(){
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)()){
printf("Hello ");
return 0;
}

59. #include<stdio.h>
void fun(int*, int);
void (*ptr[1])(int*, int);
int main(){
int a = 2;
int b = 4;
ptr[0] = fun;
ptr[0](&a, b);
printf("%d %d ", a, b);
return 0;
}
void fun(int *p, int q)
{
int tmp = *p;
*p = q;
q = tmp;
}

60. #include<stdio.h>
int main(){
EOF++;
printf("%d", EOF);
return 0;
}
61. Functions cannot return more than one value at a time. True/False?
62. Which of the following cannot be used as LHS of the expression in “for (exp1;exp2; exp3)”
a) Variable b) Function c) typedef d) macros

63. #include<stdio.h>
int main(){
int i = 65;
switch(i) {
case 65:
printf("Integer 65");
break;
case 'A':
printf("Char 65");
break;
default:
printf("Bye");
}
return 0;
}

64. #include <stdio.h>


int main(){
int i;
for (i = 1; i != 10; i = 2)
printf(" C Programming ");
return 0;
}

65. #include<stdio.h>
int main(){
int i = 65;
char ch = 'B';
switch(ch, i) {
case 65:
printf("Integer");
break;
case 'B':
printf("Char");
break;
default:
printf("Bye");
}
return 0;
}
66. #include "stdio.h"
int main(){
int i = 1, j;
for ( ; ; );
{
if (i)
j = --i;
if (j < 10)
printf("C Programming", j++);
else
break;
}
return 0;
}

67. #include<stdio.h>
void fun(char**);
int main(){
char *arr[] = { "bat", "cat", "fat", "hat", "mat", "pat" };
fun(arr);
return 0;
}
void fun(char **p){
char *t;
t = (p += sizeof(int))[-1];
printf("%s\n", t);
}

68. #include<stdio.h>
int main(){
int arr[5][5][5] = {0};
int *b = arr;
int *c = arr + 1;
printf("%d", c - b);
return 0;
}
69. #include<stdio.h>
int main(){
int i = 1;
switch(i) {
case i:
printf("case 1 executed");
break;
case i + 1;
printf("case 2 executed");
break;
default:
printf("default block executed");
break;
}
return 0;
}

70. #include<stdio.h>
int main(){
int i = 0;
printf("Hello");
char s[4] = {'\b', '\t', '\r', '\n'};
for(i = 0;i<4;i++){
printf("%c", s[i]);
}
return 0;
}

71. #include <stdio.h>


int main(){
int i = 0, j = 0;
while (i<5 < j<10) {
i++;
J++;
}
printf("%d %d", i, j);
}

72. #include<stdio.h>
int main(){
char s[] = {'a', 'b', 'c', '\n', 'c', '\0'};
char *p, *str, *str1;
p = &s[3];
str = p;
str1 = s;
printf("%d", ++*p + ++*str1-32);
return 0;
}
73. #include <stdio.h>
int main(){
char i = 0;
for (; i++; printf("%d", i));
printf("%d", i);
return 0;
}

74. #include<stdio.h>
int i;
int main(){
int t;
for (t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--", t--);
return 0;
}

75. #include<stdio.h>
int main(){
static int a[ ] = {0, 1, 2, 3, 4};
int *p[ ] = {a, a + 1, a + 2, a + 3, a + 4};
int **ptr = p;
++*ptr;
printf("%d %d %d", ptr - p, *ptr - a, **ptr);
return 0;
}

76. #include<stdio.h>
int main(){
char *str1 = "First";
char *str2 = "Second";
switch(*str1){
case "First":
printf("USAIN BOLT");
case "Second":
printf("JUSTIN GATLIN");
break;
default:
printf("Others");
}
return 0;
}

77. #include<stdio.h>
int main(){
int a, b, c;
int arr[5] = {1, 2, 3, 25, 7};
a = ++arr[1];
b = arr[1]++;
c = arr[a++];
printf("%d--%d--%d", a, b, c);
return 0;
}

78.
#include<stdio.h>
int main(){
int i = 4;
while(i == 4--)
printf("Loop ");
return 0;
}

79. #include<stdio.h>
int main(){
static char *arr[ ] = {"bike", "bus", "car", "van"};
char **ptr[ ] = {arr+3, arr+2, arr+1, arr};
char ***p;
p = ptr;
**++p;
printf("%s",*--*++p + 2);
}

80. #include<stdio.h>
#define N 1.5
int main(){
int i = 6;
switch(i){
case N + 5:
printf("Switch ON the fan");
break;
case N * 4:
printf("Switch ON the Air Cooler");
break;
default:
printf("Save Energy");
}
return 0;
}

81. #include<stdio.h>
int main(){
char ch = '\0';
switch(ch){
case NULL:
printf("Empty \0");
break;
case ' ':
printf("Empty Empty");
break;
case '0':
printf("Empty 0");
break;
default:
printf("Nothing");
}
return 0;
}

82. #include<stdio.h>
int main(){
int arr[3], i = 0;
while(i < 3){
arr[i] = ++i;
}
for(i=0; i<3; i++){
printf("%d--", arr[i]);
}
return 0;
}

83. #include<stdio.h>
#define loop for(;;)
int main(){
printf("DONE");
loop;
return 0;
}

84.
#include<stdio.h>
int main(){
while(!!7)
printf("Hai");
return 0;
}

85. #include<stdio.h>
int main(){
char ch = 96.0;
switch(ch){
case 96:
printf("inside case");
break;
default:
printf("inside default");
}
return 0;
}

86. #include<stdio.h>
int main(){
short int si = 1;
switch(++si - si++){
case 1L:
printf("First");
break;
case 2L:
printf("Second");
break;
default:
printf("Bye");
break;
}

return 0;
}

87. #include<stdio.h>
int main(){
char s[ ] = "d";
int i;
for(i = 0;s[ i ];i++)
printf("%c %c %c %c",s[ i ], *(s+i), *(i+s), i[s]);
return 0;
}

88. What is recursion?

89. void main(){


printf("%s","c" "question" "bank");
}

90. #include <stdio.h>


int mul(int a, int b, int c){
return a * b * c;
}
void main(){
int *function_pointer;
function_pointer = mul;
printf("The product of three numbers is:%d",
function_pointer(2, 3, 4));
}
91. void main(){
char *str="c-pointer";
printf("%*.*s",10,7,str);
}

92. #define message "union is\


power of c"
void main(){
clrscr();
printf("%s",message);
getch();
}

93. #include<stdio.h>
int main(){
int i = 5;
while(--i > 0)
printf("Loop ");
return 0;
}

94. #include<stdio.h>
int main(){
int x[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
printf("%d",sizeof(x));
return 0;
}

95. void main(){


int a=-12;
a=a>>3;
printf("%d",a);
}

96. #include<stdio.h>
int main(){
unsigned int num = -4;
printf("%d", ~num);
return 0;
}

97. Write a C program to keep calculating the sum of the digits of a number until the number is a single digit.

98. Which of the following % operation is invalid?


a) 3 % 9; b) 3 % 9l; c) 3 % 9f; d) Both 3 % 9l; and 3 % 9f;

99. #include <stdio.h>


int main(){
int x = 2, y = 2;
float f = y + x /= x / y;
printf("%d %f\n", x, f);
return 0;
}

100. #include "string.h"


void main(){
clrscr();
printf("%d%d",sizeof("string"),strlen("string"));
getch();
}

101. Write a C program to check whether number is EVEN or ODD, without using any arithmetic or relational operators.

102. #include <stdio.h>


int x = 0;
int main() {
int i = (f() + g()) || g();
int j = g() || (f() + g());
printf(“%d and %d”, i,j);
}
int f(){
if (x == 0)
return x + 1;
else
return x - 1;
}
int g(){
return x++;
}

103. #include <stdio.h>


void main(){
int a = 5 * 3 % 6 - 8 + 3;
printf("%d", a);
}

104. What error occurs in the absence of an exit condition in a recursive function?

105. #include <stdio.h>


int main(){
int x = 3, y = 2;
int z = x << 1 > 5;
printf("%d\n", z);
}

106. What symbol is used to Left-justify within the data given field width?
107. Which of the following operators is used to concatenate two strings without space?
108. #include <stdio.h>
void (*(f)())(int, float);
void (*(*x)())(int, float) = f;
void ((*y)(int, float));
void foo(int i, float f);
int main(){
y = x();
y(1, 2);
}

void (*(f)())(int, float){


return foo;
}
void foo(int i, float f){
printf("%d %f\n", i, f);
}

109. Write a C program to print your name 10 times without using any loop or goto statement.
110. int extern x;
void main()
printf("%d",x);
x=2;
getch();
}
int x=23;

111. What specifies the minimum number of characters to print after being padded with zeros or blank spaces?

112. Garbage collector frees the programmer from worrying about ___________.

113. #include <stdio.h>


void foo(const int *);
int main(){
const int i = 10;
printf("%d ", i);
foo(&i);
printf("%d", i);
}
void foo(const int *i){
*i = 20;
}

114. In the function malloc() and calloc, each byte of allocated space is initialized by what value?

115. #include <stdio.h>


void main(){
float hi = 0.1;
if (hi == 0.1)
printf("Sanfoundry");
else
printf("Advanced C Classes");
}
116. Global variables are ____________ . Internal/External?
117. #include <stdio.h>
int main(){
register int i = 10;
int *p = &i;
*p = 11;
printf("%d %d\n", i, *p);
}

118. If the space in memory allocated by malloc is not sufficient, then an allocation fails and returns ___________

119. #include <stdio.h>


int main(){
const int i = 10;
int *ptr = &i;
*ptr = 20;
printf("%d\n", i);
return 0;
}

120. If memory leak occurs, it is mandatory that a dangling pointer arises. True/False?

121. A function is declared as sqrt(-x) under the header file math.h, what will the function return?

122. #include <stdio.h>


void main(){
int x = 0;
if (x = 0)
printf("Its zero\n");
else
printf("Its not zero\n");
}

123. What does scanf() function return?

124. What will be returned by given C code?


size- t strlen(const char *s)
const char *sc;
for(sc = s; *sc!= ' \ O ' ; ++sc)
return(sc - s) ;

125. #include <stdio.h>


int foo(){
return 2;
}
int main(){
int x;
printf("%d",(x = foo())!= 1 );
}

126. When compiler accepts the request to use the variable as a register, where the value of the variable is stored?

127. Local variables are stored in an area called ___________?

128. Does “register” keyword mandates compiler to place it in machine register?

129. #include <stdio.h>


enum question {a = 1, b, c};
enum question example1 = 2;
enum question answer(){
return example1;
}
int main(){
(answer() == a)? printf("yes"): printf("no");
return 0;
}

130. Automatic variables are stored in ________

131. #include <stdio.h>


int x = 0;
void main(){
int *const ptr = &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}

132. #include<stdio.h>
enum sanfoundry{
a,b,c
};
enum sanfoundry g;
main(){
//g++;
printf("%d",g);
}

133. #include <stdio.h>


int main(){
int y = 1, x = 0;
int l = (y++, x++) ? y : x;
printf("%d\n", l);
}

134. #include <stdio.h>


int main(){
int d=0;
int *ptr = &(d-d);
printf("%d\n", *ptr);

135. Which among the following is never possible in C when members in a structure are same as that in a union?
Assume I)Let X be a structure II)Let Y be a union
a) sizeof(X) is greater than sizeof(Y)
b) sizeof(X) is equal to sizeof(Y)
c) sizeof(X) is less than to sizeof(Y)
d) none of the mentioned

136. #include <stdio.h>


void main(){
int h = 8;
int b = 4 * 6 + 3 * 4 < 3 ? 4 : 3;
printf("%d\n", b);
}

137. #include <stdio.h>


void foo(int*);
int main(){
int k = 10;
foo((&k)++);
}
void foo(int *p){
printf("%d\n", *p);
}

138. #include <stdio.h>


struct temp{
int a[10];
char p;
};

139. While swapping 2 numbers what precautions to be taken care?


b = (b / a);
a = a * b;
b = a / b;
a) Data type should be either of short, int and long
b) Data type should be either of float and double
c) All data types are accepted except for (char *)
d) This code doesn’t swap 2 numbers

140. #include <stdio.h>


int main(){
int i = 97, *p = &i;
foo(&p);
printf("%d ", *p);
return 0;
}
void foo(int **p){
int j = 2;
*p = &j;
printf("%d ", **p);
}

141. Which of the following cannot be used inside sizeof? Justify.


a) pointers b) functions c) macro definition d) none of the mentioned

142. #include <stdio.h>


#define HI 3.14
int main(){
printf("%d", sizeof(HI));
}

143.Which of the following is NOT possible with any 2 operators in C?


a) Different precedence, same associativity
b) Different precedence, different associativity
c) Same precedence, different associativity
d) All of the mentioned

144. Which of the following will result in run-time error?


a) int **k = &k;
b) int **k = &*k;
c) int **k = **k;
d) none of the mentioned

145. #include <stdio.h>


#include <stdlib.h>
int main(){
printf("%d\n", rand());
return 0;
}

146. #include <stdio.h>


int main(){
int z = 0;
if (z++)
printf("true\n");
else if (z == 1)
printf("false\n");
}

147. Which one is an invalid if-else statement?


a) if (if (k == 1)){}
b) if (func (k)){}
c) if (k){}
d) if ((char) k){}

148. Which option is are invalid?


a) int k[][] = {{1, 2, 3}, {2, 3, 4, 5}};
b) int *k[] = {{1, 2, 3}, {2, 3, 4, 5}};
c) int k[4][4] = {{1, 2, 3}, {2, 3, 4, 5}};
d) none of the mentioned

149. Which of the following should be used for freeing the memory allocated in the following C code?
#include <stdio.h>
struct pi{
struct pi *next;
int z;
};
int main(){
struct pi *p = (struct pi*)malloc(sizeof(struct pi));
p->z = 1;
p->next = (struct pi*)malloc(sizeof(struct pi));
return 0;
}
a)free(p); free(pp->next)
b)free(p->next);free(p);
c) free(p);
d) all of the mentioned

150. #include <stdio.h>


int main(){
int a = 1;
if (a)
printf("All is Well ");
printf("I am Well\n");
else
printf("I am not a River\n");
}

151. What does argc and argv indicate in command-line arguments?

152. #include <stdio.h>


struct pi{
char m : 2;
int n : 2;
};
int main(){
struct pi p;
p.m = 2;
p.n = 1;
p.m = p.m & p.n;
printf("%d\n", p.m);
}

153. #include <stdio.h>


void main(){
char *ch;
printf("enter a value between 1 to 3:");
scanf("%s", ch);
switch (ch){
case "1":
printf("1");
break;
case "2":
printf("2");
break;
}
}

154. What type of array is generally generated in Command-line argument?


a) Single dimension array
b) 2-Dimensional Square Array
c) Jagged Array
d) 2-Dimensional Rectangular Array

155. What is argv[0] in command line arguments?

156. #include <stdio.h>


int main(){
typedef struct p *q;
struct p{
int x;
char y;
q ptr;
};
struct p p = {1, 2, &p};
printf("%d\n", p.ptr->x);
return 0;
}

157. Run without any command line arguments


#include <stdio.h>
int main(int argc, char *argv[]){
while (argc--)
printf("%s\n", argv[argc]);
return 0;
}

158. #include <stdio.h>


typedef struct p *q;
struct p{
int x;
char y;
q ptr;
};
int main(){
struct p p = {1, 2, &p};
printf("%d\n", p.ptr->ptr->x);
return 0;
}

159. Run without any command line arguments


#include <stdio.h>
int main(int argc, char *argv[]){
while (argv != NULL)
printf("%s\n", *(argv++));
return 0;
}

In the following questions write C programs with proper indentation and comments.
160. A program that has no command line arguments will have argc no values. True/False
161. Replace all 0’s with 1 in a given integer
162. Binary to decimal conversion
163. Program to find all the patterns of 0(1+)0 in the given string (0(1+)0 – There should be at least one ‘1’ between the two 0’s. Eg.
I/P: 01101111010 O/P: 3)
164. Program to count the common sub sequence of two strings(Eg. I/P: string 1 = “abcd”
string 2 = “abc” O/P: Number of common sub-sequences = 7)
165. Program to find all triplets with the given sum in the given array(Eg. Consider the array: arr[] = {0, -1, 2, -3, 1}. The given
sum is -2. In the given array, the triplets with sum = -2 are {0, -3, 1} and {-1, 2, -3}. I/P:0, -1, 2, -3, 1 O/P:{0, -3, 1} and {-1, 2, -
3})
166. Program to find all symmetric pairs in an array(Eg. I/P:arr [6] [2] = {{1, 2}, {3, 4}, {5, 6}, {2, 1}, {4, 3},{10,11}} O/P:{1,2}
and {2,1}, {3,4} abd {4,3})
167. Program to find the maximum product subarray in a given array (Eg. I/P: {-1, -3, -10, 60,0}
O/P: {-3, -10, 60} Product of the sub-array = 1800)
168. Program to find the equilibrium index of an array (Equilibrium index of an array is an index such that Sum of elements at
lower indexes = Sum of elements at higher indexes.Eg. I/P:a[] = {-7, 1, 5, 2, -4, 3, 0} O/P: a[0] + a[1] + a[2] = a[4] + a[5] + a[6]
Equilibrium index= 3 )
169. Printing an array into Zigzag fashion (In a zig-zag pattern, the first integer is less than the second integer, which is greater than
the third integer, which is less than the fourth integer, and so on. Hence, the converted array should be in the form of e1 < e2 > e3 <
e4 > e5 < e 6.I/P: 7 4 3 7 8 6 2 1O/P: 3 7 4 8 2 6 1)
170. Program to find the saddle point coordinates in a given matrix (A saddle point is an element of the matrix, which is the
minimum element in its row and the maximum in its column. Eg. I/P: {{1, 2 , 3 },{4,5,6},{7,8,9}} O/P: 7)
171. Program to print the elements of a 2d array in the form of a matrix in spiral form (I/P: 1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
O/P: 1 2 3 4 5 6 12 18 17 16 15 14 13 7 8 9 10 11)