Professional Documents
Culture Documents
23NU1A05B8 CP Lab
23NU1A05B8 CP Lab
1
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
3
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
10. Write C programs on Simple functions using Call by reference, Dangling pointers
11. Write C programs on Pointers, structures and dynamic memory allocation
12. Write C programs on Bit fields, Self-Referential Structures
13. Write C programs to implement File operations
4
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
23ESX05.2 Apply the right control structure for solving the problem
Implement simple programs to solve computing problems using user defined
23ESX05.3
functions
23ESX05.4 Develop programs using arrays and pointers
23ESX05.5 Experiment with user defined data types and file operations
5
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
PROGRAM OUTCOMES
SNO OUTCOMES DESCRIPTION
1 Engineering Knowledge Apply the knowledge of mathematics , science, engineering fundamentals and an
engineering specialization to the solution of complex engineering problems .
2 Problem Analysis Identify , formulate, research literature &analyze complex engineering problems reaching
substantiated conclusions using first principles of mathematics , natural science , engineering
science .
3 Design/Development of solution Design solutions for complex engineering problems and design system components of
processes that meet the specified needs with appropriate consideration for the public health
safety and the cultural, societal and environmental considerations
4 Conduct Investigations of Use research –based knowledge and research methods including design of experiments and
interpretation of data and synthesis of the information to provide valid conclusions
complex problems
5 Modern tool usage Create, select and apply appropriate techniques, resources and modern engineering and IT
tools including prediction and modeling to complex engineering activities with an
understanding of the limitations .
6 The Engineering and society Apply reasoning informed by the contextual knowledge to assess societal ,health ,safety ,
legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice
6
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
PROGRAM OUTCOMES
SNO OUTCOMES DESCRIPTION
7 Environmental and sustainability Understand the impact of professional engineering solutions and environmental contexts
and demonstrate the knowledge of and need for sustainable development
8 Ethics Apply ethical principles and commit to professional ethics and responsibilities and norms of
engineering practice.
9 Individual and teamwork Function effectively as an individual , and as a member or leader in diverse terms and in
multidisciplinary settings
10 Communication Communicate effectively on complex engineering activities with the engineering community
and with society at large such as being able to comprehend and write effective reports and
documentation, make effective presentation, and give and receive clear instructions .
11 Project management and Demonstrate knowledge and understanding of the engineering and management principles
and apply theses to one’s own work ,as a member and leader in a team ,to manage projects
finance and in multidisciplinary environments.
12 Lifelong Learning Recognize the need for and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change.
7
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
8
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
Example:
int i=1; //Declaration for a loop body
while(i<=5) {
//loop body
//code to be executed repeatedly
} 11
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
Program:
Input:
#include<stdio.h>
int main() {
int n,count=0;
printf(“Enter n value \n”);
scanf(“%d”,&n);
while(n!=0) {
count ++;
n=n/10;
}
printf(“count=%d”,count);
return 0;
} 13
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
Output
14
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
example:
int n=5
for(i=0;i<n;i=++)
{
//Block of statements to execute
}
17
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
18
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
19
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
Program:
Input:
#include<stdio.h>
int main()
{
int i,n first=0,second=1,next;
printf("Enter the number of terms :");
scanf("%d",&n);
printf("fibanocci series:");
for(int i=0;i<n;i++)
{ 20
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
printf("%d",first);
next=first+second;
first=second;
second=next;
}
return 0;
}
21
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
output 1:
22
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
output 2:
23
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
File Handling: Reading or writing data from/to files line by line or character by
character.
24
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
user input validation: Repeatedly prompting the user until valid input
is provided.
25
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
BIT FIELDS
AND
SELF-REFERENTIAL STRUCTURES
26
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
BIT FIELDS
Bit fields are a way to declare a structure or union member with a
specific width in terms of the number of bits it occupies in memory. Bit
fields allow you to create more compact data structures by explicitly
specifying the number of bits each member should occupy
Here's the basic syntax for defining bit fields within a structure:
27
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
In the above example, ‘flag’ is a bit field that occupies 1 bit, and value is a bit field
that occupies 4 bits.
Here's a more detailed breakdown:
• ‘member_ name’: This is the name of the bit field member within the
structure.
• ‘width’: This is the number of bits that the member should occupy.
Bit fields are useful in scenarios where memory conservation is crucial, and you
want to optimize the storage of data. However, they come with some
considerations and limitations:
• The actual memory layout may depend on the architecture and compiler.
• The width of a bit field member cannot exceed the size of the underlying data
type (e.g., ‘int’, ‘char’).
• The order of bit fields within a structure is not guaranteed.
Here's an example of using bit fields in a complete program:
28
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
In this example, the Flags structure contains three bit fields: flag1 and flag2 with 1 bit each, and value with 4
29
bits. The program initializes these bit fields and prints their values.
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
SELF-REFERENTIAL STRUCTURE:
Self-referential structures, also known as recursive structures, are
structures in programming languages like C or C++ that have a member
that is a pointer to the same type of structure. This allows the structure to
contain elements that refer to other instances of the same structure type.
Self-referential structures are commonly used to build data structures
like linked lists, trees, and graphs.
30
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
31
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
In this example:
• The ‘Node’ structure contains an integer data member (‘data’) and a pointer to the
next ‘Node’ in the list (‘next’).
• In the ‘main’ function, three instances of ‘Node’ (node1, node2, and node3) are
created, and data is assigned to each node.
• The nodes are linked to form a linked list by assigning the ‘next’ pointers
accordingly.
• The program then traverses the linked list, starting from the first node (‘node1’)
and printing the data of each node.