Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CSD 101 ENDSEMS 2017, Exams of Programming Languages

CSD 101 ENDSEMS 2017, High chance of question getting repeated or getting similar type of questions

Typology: Exams

2016/2017

Available from 08/10/2021

meetendra-singh
meetendra-singh 🇮🇳

17 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programme: B. Tech Discipline: Computer Science and Engineering
Exam: End Semester Year: 2017-2018
Course Code: CSD101 Course Title: Introduction to Computing & Programming
Date: December 03, 2017 Time: 9.30 AM - 12.30 PM Max. Marks: 100
Ques.1 Do each of the following: (1*8 = 8 Marks)
a) Write the function header for a function called exchange that takes two pointers to floating-point
numbers x and y as parameters and does not return a value.
b) Write the function prototype for the function in part (a).
c) Write the function header for a function called evaluate that returns an integer and that takes as
parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns
an integer.
d) Write the function prototype for the function in part (c).
e) Write the function header for function zero which takes a long integer array parameter bigIntegers and
does not return a value.
f) Write the function prototype for the function in part (e).
g) Write the function header for function add1AndSum which takes an integer array parameter
oneTooSmall and returns an integer.
h) Write the function prototype for the function described in part (g).
Ques.2 How many bytes in memory would be occupied by the following array of pointers to strings? How many bytes
would be required to store the same strings, if they are stored in a two-dimensional character array? (2 Marks)
Char *mess[ ] = { “Hammer and Tongs”, “Tooth and Nail”, “Spit and Polish”, “ You and C” };
Ques.3 Can an array of pointers to strings be used to collect strings from the keyboard? If not, why? (2 Marks)
Ques.4 Show two different methods of initializing character array vowel with the string of vowels, “AEIOU”.
(2 Marks)
Ques.5 State whether the following statements are True/False : (1*10 = 10 Marks)
1. When the printf function is called it always begins printing at the beginning of a new line.
2. A string when read using scanf() needs an ampersand character.
3. Comments are instructions that cause some action to take place.
4. If S1 and S2 are two strings, then concatenation operation produces a string which contains characters of
S2 followed by the characters of S1.
5. A function cannot be defined inside another function.
6. If return type for a function is not specified, it defaults to int.
7. C considers the variables number and NuMbEr to be identical.
8. A string Hello World can be read using scanf.
9. To ensure that a character is uppercase, the toupper conversion function is used.
10. Are the three declarations char **apple, char *apple[ ], and char apple[ ][ ] same?
Ques.6 Write a C program to find the length of a given string. (Do not use “strlen” function) (2 Marks)
Ques.7 Write a C program to copy the contents of a given string into another string. (Do not use “strcpy” function)
(2 Marks)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download CSD 101 ENDSEMS 2017 and more Exams Programming Languages in PDF only on Docsity!

Programme: B. Tech Discipline: Computer Science and Engineering Exam: End Semester Year: 2017- Course Code: CSD101 Course Title: Introduction to Computing & Programming Date: December 03, 2017 Time: 9.30 AM - 12.30 PM Max. Marks: 100 Ques.1 Do each of the following: (18 = 8 Marks) a)* Write the function header for a function called exchange that takes two pointers to floating-point numbers x and y as parameters and does not return a value. b) Write the function prototype for the function in part (a). c) Write the function header for a function called evaluate that returns an integer and that takes as parameters integer x and a pointer to function poly. Function poly takes an integer parameter and returns an integer. d) Write the function prototype for the function in part (c). e) Write the function header for function zero which takes a long integer array parameter bigIntegers and does not return a value. f) Write the function prototype for the function in part (e). g) Write the function header for function add1AndSum which takes an integer array parameter oneTooSmall and returns an integer. h) Write the function prototype for the function described in part (g). Ques.2 How many bytes in memory would be occupied by the following array of pointers to strings? How many bytes would be required to store the same strings, if they are stored in a two-dimensional character array? (2 Marks) Char mess[ ] = { “Hammer and Tongs”, “Tooth and Nail”, “Spit and Polish”, “ You and C” }; Ques.3 Can an array of pointers to strings be used to collect strings from the keyboard? If not, why? (2 Marks) Ques.4 Show two different methods of initializing character array vowel with the string of vowels, “AEIOU”. (2 Marks) Ques.5 State whether the following statements are True/False : (110 = 10 Marks)

1. When the printf function is called it always begins printing at the beginning of a new line. 2. A string when read using scanf() needs an ampersand character. 3. Comments are instructions that cause some action to take place. 4. If S1 and S2 are two strings, then concatenation operation produces a string which contains characters of S2 followed by the characters of S1. 5. A function cannot be defined inside another function. 6. If return type for a function is not specified, it defaults to int. 7. C considers the variables number and NuMbEr to be identical. 8. A string Hello World can be read using scanf. 9. To ensure that a character is uppercase, the toupper conversion function is used. 10. Are the three declarations char **apple, char *apple[ ], and char apple[ ][ ] same? Ques.6 Write a C program to find the length of a given string. (Do not use “strlen” function) (2 Marks) Ques.7 Write a C program to copy the contents of a given string into another string. (Do not use “strcpy” function) (2 Marks)

Ques.8 Find the output for the following program segments: (1 * 8 = 8 Marks) a) #include<stdio.h> void main() { int const a = 5; a++; printf(“%d”, a); } b) #include<stdio.h> void main() { const int a = 5; a++; printf(“%d”, a); } c) #include<stdio.h> void main() { char s[ ]="hello", t[ ]="hello"; if(s = = t) printf("equal strings"); else printf("No Output"); } d) #include<stdio.h> void main() { int x = ~1; printf(“%d”, x); } e) #include<stdio.h> void f() { static int i; ++i; printf("%d", i); } void main() { f(); f(); f(); } f) #include<stdio.h> void main() { register int x = 5; int *p; p=&x; x++; printf("%d", p); } i) Compiler Error ii) 5 iii) 6 iv) Garbage Value g) #include<stdio.h> void f() { printf("Hello\n"); } void main() { ; } i) No output ii) Error, as the function is not called iii) Error, as the function is defined without its declaration iv) Error, as the main() function is left empty h) #include<stdio.h> void main() { int i = 13, j = 60; i ^= j; j ^= i; i ^= j; printf("%d %d", i, j); } Ques.9 Fill in the following blanks : (112 = 12 Marks)

1. The bits in the result of an expression using the _______________ operator are set to 1 if the corresponding bits in each operand are set to 1. Otherwise, the bits are set to zero. 2. The _______________ operator returns the location in memory where its operand is stored. 3. To simulate call by reference when passing a non-array variable to a function, it is necessary to pass the _______________ of the variable to the function. 4. The conversion specifiers _________ and __________ are used to print strings and characters, respectively.

    • ( * ( x ) + 2 ) + 1 d. 3
    • ( * ( x + 1 ) + 3 ) e. 2
  1. *n f. 12
    • ( n + 2 ) g. 14
  2. ( * ( n + 3 ) + 1 ) h. 7
    • ( n + 5 ) + 1 i. 1
  3. ++ n j. 8 k. 5 l. 10 m. 6 Ques.12 Match the following with reference to the following segment: (110 = 10 Marks) unsigned int arr[3][3] = { 2, 4, 6, 9, 1, 10, 16, 64, 5 };
  4. **arr a. 64
  5. **arr < * ( *arr + 2 ) b. 18
    • ( arr + 2 ) / ( * ( *arr + 1 ) > **arr) c. 6
    • ( arr[1] + 1 ) | arr[1][2] d. 3
    • ( arr[0] ) | * (arr[2] ) e. 0
  6. arr[1][1] < arr[0][1] f. 16
  7. arr[2][1] & arr[2][0] g. 1
  8. arr[2][2] | arr[0][1] h. 11
  9. arr[0][1] ^ arr[0][2] i. 20
  10. ++ **arr + --arr[1][1] j. 2 k. 5 l. 4 Ques.13 What does this program do? (2 Marks) #include<stdio.h> int mystery(const char *, const char *); void main() { char string1[80], string2[80]; printf("Enter two strings\n"); scanf("%s%s", string1, string2); printf("The result is %d\n", mystery(string1,string2)); } int mystery(const char *s1, const char *s2) { for( ; *s1!='\0' && s2!='\0'; s1++, s2++) if(s1 != *s2) return 0; return 1; } Ques.14 What is a double pointer? Explain by giving an example. (2 Marks) Ques.15 What is the full form of ASCII? (2 Marks) Ques.16 What is the built-in function to append one string to another? (2 Marks)

Ques.17 What is the default value of local and global variables? (2 Marks) Ques.18 Convert the following into its given equivalent codes. Show steps of conversion also. (4 Marks)

END TERM SOLUTION

Q1. (a) void exchange(float *x, float *y) (b) void exchange(float , float ); (c) int evaluate( int x, int (poly)(int a)) (d) int evaluate( int , int ()(int )); (e) void zero( long int bigIntegers[ ]) (f) void zero( long int [ ]); (g) int add1AndSum(int oneTooSmall[ ]) (h) int add1AndSum(int [ ]); Q2. 58 Bytes 68 Bytes to store in a two-dimensional array. Q3. No, we can not collect strings from the keyboard in an array of pointers to strings. The reason is that when we initialize such array pf pointers, then at the time of initialization, the pointers will start pointing to some garbage location. Those uninitialized pointers are not actually pointing anywhere. That array is filled with garbage, which means that all those pointers could be pointing anywhere at all, most likely to memory that doesn't belong to you and hence that you have not been granted access to. Q4. (i) char vowel[ ] = “AEIOU”; (ii) char *vowel = “AEIOU”; Q5. 1. False

  1. False
  2. False
  3. False
  4. True
  5. True
  6. False

Q9. 1. Bitwise AND

  1. “Address of” OR “Ampersand” OR “&”
  2. Address
  3. %s and %c
  4. Bitwise XOR
  5. Sorting
  6. “Indirection” OR “Dereference Operator” OR “*”
  7. Name and Type (Data Type)
  8. Automatic
  9. continue Q10. a) F9C b) F9E c) F9E d) 35 e) 45 f) F9C g) 45 h) F9E i) 47 j) Garbage Value Q11.
    1. 12
    2. 14
    3. 6
    4. 4
    5. 9
    6. 1
    7. 3
    8. 5
    9. 7
    10. 2 Q12.
    11. 2
    12. 1
    13. 16
    14. 11
    15. 18
    16. 1
    17. 0
    18. 5
    19. 2
    20. 3

Q13. It will compare 2 strings and return 1 if they are same else return 0. Q14. A double pointer is a pointer variable that holds the address of another pointer variable. For Example: int a = 10; int *j = &i; int *k = &j; Here, double pointer k stores of another pointer variable j. Q15. American Standard Code for Information Interchange. Q16. strcat( ) Q17. Local – Garbage Value Global – zero ( 0 ) Q18. (i) (84) 10 = (1110) 4 (ii) (2C9) 16 = (713) 10 (iii) (101010) 2 = (52) 8 (iv) (3674) 8 = (011110111100) 2 Q19. #include<stdio.h> void main() { int n, i, j, temp, pos; printf("Enter the size of array\n"); scanf("%d", &n); int arr[n]; printf("Enter array elements\n"); for(i=0; i<n; i++) scanf("%d", &arr[i]); printf("Array before Sorting\n"); for(i=0; i<n; i++) printf("%d\n", arr[i]); for(i=0; i<n; i++) { pos = i; for(j=i+1; j<n; j++) { if(arr[j] < arr[pos]) pos = j; } if(pos != i) { temp = arr[i]; arr[i] = arr[pos]; arr[pos] = temp;

else if(y > 0) z = y; else { z = x; y = x + 1; } z = z + 1; printf("%d\n%d\n%f", x, y, z); }