# PRODUCT DETAILS

Online-Typing-and-Filling

 Title Name Amity Solved Assign Programming and Problem Solving through C Language University AMITY Service Type Assignment Course B.Sc-(IT) Semester Semester-I Course: B.Sc-(IT) Session 2016-2017 Short Name or Subject Code Programming & Problem Solving through C Language Commerce line item Type Semester-I Course: B.Sc-(IT) Product Assignment of B.Sc-(IT) Semester-I (AMITY) Price PRICE INR Click to View Price

# Solved Assignment

Questions :-

Amity B.SC IT 1 Sem Solve Assignment For Programming & Problem Solving through C Language Sem 1

Section A

 1 . Evaluate the expression 2+3*3-7+10-5/4+3 Using operator precedence.
 2 . What are the storage classes available in c language?
 3 . Compare while and Do – While loop with examples?
 4 . Compare break, continue, and goto statement?
 5 . What is pointer? Explain with example

Section B

Case Detail :

QUESTIONS

 1 a) What is structured programming? Explain and give examples of relevant constructs using pseudo-code. Highlight the advantages and disadvantages of structured programming. b) What is an execution error? Differentiate it from syntactic error. Give examples. c) It is said that ‘C’ is a middle level assembly language. Mention those features of ‘C’which enables this description.
 2 a) Write and explain the action of WHILE statement. Develop a program in ‘C’ language to compute the average of every third integer number lying between 1 and 100. Include appropriate documentation. b) Develop a function to calculate sum of n even integers starting from a given even integer. c) Identify all the compound statements which appear in the following program segment: { sum=0; do { scanf(‚%d?, &i); if (i < 0) { i=-i; ++flag; } sum += i; } while (i != 0); }
 3 a) What is a pointer in ‘C’? How is a pointer variable declared? Give examples and explain.Enumerate the utility of pointer variables . b) A program in ‘C’ language contains the following declaration: static int x[8] = {1,2,3,4,5,6,7,8}; i) What is the meaning of x? ii) What is the meaning of (x + 2)? iii) What is the meaning of *x? iv) What is the meaning of (*x + 2)? v) What is the meaning of *(x + 2)? c) What is a structure? How does a structure differ from a union? Give examples. For what kind of applications, union data structure is useful? How are arrays different from structure?

Assignment-C

Question No.  1

Code:   int z,x=5,y=-10,a=4,b=2; z = x++ - --y * b / a;

What number will z in the sample code above contain?

1. 5
2. 6
3. 10
4. 11

Question No.  2           Marks - 10

With every use of a memory allocation function, what function should be used to release allocated memory which is no longer needed?

Options

1. unalloc()
2. dropmem()
3. dealloc()
4. free()

Question No.  3

Code: void *ptr;

myStruct myArray[10];

ptr = myArray;

Which of the following is the correct way to increment the variable "ptr"?

Options

1. ptr = ptr + sizeof(myStruct);
2. ++(int*)ptr;
3. ptr = ptr + sizeof(myArray);
4. increment(ptr);

Question No.  4

Code:

char* myFunc (char *ptr)

{

ptr += 3; return (ptr);

}

int main()

{

char *x, *y; x = "HELLO";

y = myFunc (x);

printf ("y = %s ", y); return 0;

}

Options

1. y = HELLO
2. y = ELLO
3. y = LLO
4. y = LO

Question No.  5           Marks - 10

struct node *nPtr, *sPtr;   /* pointers for a linked list. */ for (nPtr=sPtr; nPtr; nPtr=nPtr->next)

{

free(nPtr);

}

The sample code above releases memory from a linked list. Which of the choices below accurately describes how it will work?

Options

1. It will work correctly since the for loop covers the entire list.
2. It may fail since each node "nPtr" is freed before its next address can be accessed.
3. In the for loop, the assignment "nPtr=nPtr->next" should be changed to "nPtr=nPtr.next".

Question No.  6           Marks - 10

What function will read a specified number of elements from a file?

Options

2. getline()

Question No.  7           Marks - 10

"My salary was increased by 15%!" Select the statement which will EXACTLY reproduce the line of text above.

Options

1. printf(""My salary was increased by 15/%!" ");
2. printf("My salary was increased by 15%! ");
3. printf("My salary was increased by 15´%´! ");
4. printf(""My salary was increased by 15%%!" ");

Question No.  8           Marks - 10

What is a difference between a declaration and a definition of a variable?

Options

1. Both can occur multiple times, but a declaration must occur first.
2. There is no difference between them.
3. A definition occurs once, but a declaration may occur many times.
4. A declaration occurs once, but a definition may occur many times.

Question No.  9           Marks - 10

int testarray[3][2][2] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; What value does testarray[2][1][0] in the sample code above contain?

Options

1. 3
2. 5
3. 11
4. 9

Question No.  10         Marks - 10

Code:

int a=10,b; b=a++ + ++a;

printf("%d,%d,%d,%d",b,a++,a,++a);

What will be the output when following code is executed

Options

1. 12,10,11,13
2. 22,13,13,13
3. 22,10,11,13
4. 22,11,11,11

Question No.  11         Marks - 10

Code:

int x[] = { 1, 4, 8, 5, 1, 4 };

int *ptr, y;

ptr = x + 4;

y = ptr - x;

What does y in the sample code above equal?

Options

1. -3
2. 0
3. 4
4. 4 + sizeof( int )

Question No.  12         Marks - 10

Code:

void myFunc (int x)

{

if (x > 0) myFunc(--x);

printf("%d, ", x);

}

int main()

{

myFunc(5); return 0;

}

What will the above sample code produce when executed?

Options

1. 1, 2, 3, 4, 5, 5,
2. 4, 3, 2, 1, 0, 0,
3. 5, 4, 3, 2, 1, 0,
4. 0, 0, 1, 2, 3, 4,

Question No.  13         Marks - 10

What does the operation shown above produce?

Options

1. 1
2. 6
3. 8
4. 14

Question No.  14         Marks - 10

#define MAX_NUM 15 Referring to the sample above, what is MAX_NUM?

Options

1. MAX_NUM is an integer variable.
2. MAX_NUM is a linker constant.
3. MAX_NUM is a precompiler constant.
4. MAX_NUM is a preprocessor macro.

Question No.  15         Marks - 10

Which one of the following will turn off buffering for stdout?

Options

1. setbuf( stdout, FALSE );
2. setvbuf( stdout, NULL );
3. setbuf( stdout, NULL );
4. setvbuf( stdout, _IONBF );

Question No.  16         Marks - 10

What is a proper method of opening a file for writing as binary file?

Options

1. FILE *f = fwrite( "test.bin", "b" );
2. FILE *f = fopenb( "test.bin", "w" );
3. FILE *f = fopen( "test.bin", "wb" );
4. FILE *f = fwriteb( "test.bin" );

Question No.  17         Marks - 10

Which one of the following functions is the correct choice for moving blocks of binary data that are of arbitrary size and position in memory?

Options

1. memcpy()
2. memset()
3. strncpy()
4. memmove()

Question No.  18         Marks - 10

int x = 2 * 3 + 4 * 5; What value will x contain in the sample code above?

Options

1. 22
2. 26
3. 46
4. 50

Question No.  19         Marks - 10

Code:

void * array_dup (a, number, size) const void * a;

size_t number; size_t size;

{

void * clone; size_t bytes; assert(a != NULL);

bytes = number * size; clone = alloca(bytes); if (!clone)

return clone;

memcpy(clone, a, bytes);

return clone;

}

The function array_dup(), defined above, contains an error. Which one of the following correctly analyzes it?

Options

1. If the arguments to memcpy() refer to overlapping regions, the destination buffer will be subject to memory corruption.
2. array_dup() declares its first parameter to be a pointer, when the actual argument will be an array.
3. The memory obtained from alloca() is not valid in the context of the caller. Moreover, alloca() is nonstandard
4. The definition of array_dup() is unusual. Functions cannot be defined using this syntax.

Question No.  20         Marks - 10

int var1; If a variable has been declared with file scope, as above, can it safely be accessed globally from another file?

Options

1. Yes; it can be referenced through the register specifier.
2. No; it would have to have been initially declared as a static variable.
3. No; it would need to have been initially declared using the global keyword.
4. Yes; it can be referenced through the publish specifier.

Question No.  21         Marks - 10

time_t t; Which one of the following statements will properly initialize the variable t with the current time from the sample above?

Options

1. t = clock();
2. time( &t );
3. t = ctime();
4. t = localtime();

Question No.  22         Marks - 10

Which one of the following provides conceptual support for function calls?

Options

1. The system stack
2. The data segment
3. The processor´s registers
4. The text segment

Question No.  23         Marks - 10

C is which kind of language?

Options

1. Machine
2. Procedural
3. Assembly
4. Object-oriented

Question No.  24         Marks - 10

Code:

int i,j;  int ctr = 0;

int myArray[2][3]; for (i=0; i<3; i++)

for (j=0; j<2; j++)

{

myArray[j][i] = ctr;

++ctr;

}

What is the value of myArray[1][2]; in the sample code above?

Options

1. 5 00,10,01,11,12
2. 1
3. 2
4. 3

Question No.  25         Marks - 10

Code:

int x = 0;

for (x=1; x<4; x++);

printf("x=%d ", x);

What will be printed when the sample code above is executed?

Options

1. x=0
2. x=1
3. x=3
4. x=4

Question No.  26         Marks - 10

Code:

int x = 3; if( x == 2 );

x = 0;

if( x == 3 )

x++;

else x += 2;

What value will x contain when the sample code above is executed?

Options

1. 1
2. 2
3. 3
4. 4

Question No.  27         Marks - 10

Code:

char *ptr;

char myString[ ] = "abcdefg";

ptr = myString; ptr += 5;

What string does ptr point to in the sample code above?

Options

1. fg /*because string*/
2. efg
3. defg
4. cdefg

Question No.  28         Marks - 10

Code:

double x = -3.5, y = 3.5;

printf( "%.0f : %.0f ", ceil( x ), ceil( y ) );

printf( "%.0f : %.0f ", floor( x ), floor( y ) );

What will the code above print when executed?  ceil =>rounds up 3.2=4 floor =>rounds down 3.2=3

1. -3 : 4-4 : 3
2. -4 : 4-3 : 3
3. -4 : 3-4 : 3
4. -4 : 3-3 : 4

Question No.  29         Marks - 10

Which one of the following will declare a pointer to an integer at address 0x200 in memory?

Options

1. int *x; *x = 0x200;
2. int *x = &0x200;
3. int *x = *0x200;
4. int *x = 0x200; Choice 5

Question No.  30         Marks - 10

Code:

int x = 5;

int y = 2;

char op = ´*´;

switch (op)

{

default : x += 1;

case ´+´ : x += y; /*It will go to all the cases*/

case ´-´ : x -= y;

}

After the sample code above has been executed, what value will the variable x contain?

Options

1. 4
2. 5
3. 6
4. 7

Question No.  31         Marks - 10

Code:

x = 3, counter = 0; while ((x-1))

{

++counter; x--;

}

Referring to the sample code above, what value will the variable counter have when completed?

Options

1. 0
2. 1
3. 2
4. 3

Question No.  32         Marks - 10

char ** array [12][12][12]; Consider array, defined above. Which one of the following definitions and initializations of p is valid?

Options

1. char ** (* p) [12][12] = array;
2. char ***** p = array;
3. char * (* p) [12][12][12] = array;
4. const char ** p [12][12][12] = array;

Question No.  33         Marks - 10

void (*signal(int sig, void (*handler) (int))) (int); Which one of the following definitions of sighandler_t allows the above declaration to be rewritten as follows: sighandler_t signal (int sig, sighandler_t handler);

Options

1. typedef void (*sighandler_t) (int);
2. typedef sighandler_t void (*) (int);
3. typedef void *sighandler_t (int);
4. #define sighandler_t(x) void (*x) (int)

Question No.  34         Marks - 10

All of the following choices represent syntactically correct function definitions. Which one of the following represents a semantically legal function definition in Standard C?

Options

1. Code:

int count_digits (const char * buf) {

assert(buf != NULL);

int cnt = 0, i;

for (i = 0; buf[i] != ´´; i++)

if (isdigit(buf[i]))

cnt++;

return cnt;

}

2. Code:

int count_digits (const char * buf) {

int cnt = 0;

assert(buf != NULL);

for (int i = 0; buf[i] != ´´; i++)

if (isdigit(buf[i]))

cnt++;

return cnt;

}

3. Code:

int count_digits (const char * buf) {

assert(buf != NULL);

for (i = 0; buf[i] != ´´; i++)

if (isdigit(buf[i]))

cnt++;

return cnt;

}

4. Code:

int count_digits (const char * buf) {

assert(buf != NULL);

int cnt = 0;

for (int i = 0; buf[i] != ´´; i++)

if (isdigit(buf[i]))

cnt++;

return cnt;

}

Question No.  35         Marks - 10

struct customer *ptr = malloc( sizeof( struct customer ) ); Given the sample allocation for the pointer "ptr" found above, which one of the following statements is used to reallocate ptr to be an array of 10 elements?

Options

1. ptr = realloc( ptr, 10 * sizeof( struct customer));
2. realloc( ptr, 9 * sizeof( struct customer ) );
3. ptr += malloc( 9 * sizeof( struct customer ) );
4. ptr = realloc( ptr, 9 * sizeof( struct customer ) );

Question No.  36         Marks - 10

Which one of the following is a true statement about pointers?

Options

1. Pointer arithmetic is permitted on pointers of any type.
2. Pointers may be used to simulate call-by-reference.
3. A pointer of type void * can be used to directly examine or modify an object of any type.
4. Standard C mandates a minimum of four levels of indirection accessible through a pointer.

Question No.  37         Marks - 10

Which one of the following functions returns the string representation from a pointer to a time_t value?

Options

1. localtime
2. gmtime
3. ctime
4. strtime

Question No.  38         Marks - 10

Code:

short testarray[4][3] = { {1}, {2, 3}, {4, 5, 6} }; printf( "%d ", sizeof( testarray ) );

Assuming a short is two bytes long, what will be printed by the above code?

Options

1. It will not compile because not enough initializers are given.
2. 6
3. 24
4. 7

Question No.  39         Marks - 10

char buf [] = "Hello world!"; char * buf = "Hello world!"; In terms of code generation, how do the two definitions of buf, both presented above, differ?

Options

1. The first definition certainly allows the contents of buf to be safely modified at runtime; the second definition does not.
2. The first definition is not suitable for usage as an argument to a function call; the second definition is.
3. The first definition is not legal because it does not indicate the size of the array to be allocated; the second definition is legal.
4. They do not differ -- they are functionally equivalent.

Question No.  40         Marks - 10

In a C expression, how is a logical AND represented?

Options

1. @@
2. ||
3. .AND.
4. &&

Only after macking the payment you would be able to see the answer...!!!

## 4.8 / 5

#### Rating breakdown

5
80% Complete (danger)
1
4
80% Complete (danger)
1
3
80% Complete (danger)
0
2
80% Complete (danger)
0
1
80% Complete (danger)
0

January 29, 2015