This document provides an overview of embedded systems programming. It discusses that embedded computers are used as part of larger systems to control physical devices. Reliability is often critical and resources are limited. Application areas include microcontrollers, real-time response requirements, and possible organization of embedded systems. C is discussed as a commonly used programming language for embedded systems due to its efficiency, ability to handle low-level activities, and ability to be compiled on different computers.
AMC Squarelearning Bangalore is the best training institute for a career development. it had students from various parts of the country and even few were from West African countries.
This PPT is all about INTRODUCTION TO C LANGUAGE in which all basic topics are covered and the information present in this is refered from a book called "Let Us C" by YASHAVANT KANETKAR i.e. This PPT is having all important points of first chapter of "Let Us C". If any doubt plz ask us in comment.
This Document about is C Programming language. You will learn Operators in C.
Types of operators-
Arithmetic Operators
Relational Operators
Increment Operator
Decrement Operator
Logical Operators
Conditional Operator
AMC Squarelearning Bangalore is the best training institute for a career development. it had students from various parts of the country and even few were from West African countries.
This PPT is all about INTRODUCTION TO C LANGUAGE in which all basic topics are covered and the information present in this is refered from a book called "Let Us C" by YASHAVANT KANETKAR i.e. This PPT is having all important points of first chapter of "Let Us C". If any doubt plz ask us in comment.
This Document about is C Programming language. You will learn Operators in C.
Types of operators-
Arithmetic Operators
Relational Operators
Increment Operator
Decrement Operator
Logical Operators
Conditional Operator
Learning c - An extensive guide to learn the C LanguageAbhishek Dwivedi
This document covers entire C language thoroughly. Its for all the students or professionals who would like to learn C or would like to brush up their knowledge with a quick recap.
The C programming language is a structure oriented programming language, developed at Bell Laboratories in 1972 by Dennis Ritchie C programming language features were derived from an earlier language called “B” (Basic Co..
This course teaches engineering students how to program in C. I gave this course for several years in the framework of the "Advanced Technology Higher Education Network" / SOCRATES program.
It is a very simple and easy language, C language is mainly used for develop desktop based application. All other programming languages were derived directly or indirectly from C programming concepts. This language have following features;
http://www.tutorial4us.com/cprogramming/c-features
This presentation is about -
embedded system programming,
What are device drivers?,
Types of device driver,
Recognizing device drivers,
Character Device Drivers,
Features of kernel programming,
This session reviews some key features of the C++ language that are of interest to the embedded software developer. Also, some language features and implementation details that may be troublesome are highlighted and explained.
Learning c - An extensive guide to learn the C LanguageAbhishek Dwivedi
This document covers entire C language thoroughly. Its for all the students or professionals who would like to learn C or would like to brush up their knowledge with a quick recap.
The C programming language is a structure oriented programming language, developed at Bell Laboratories in 1972 by Dennis Ritchie C programming language features were derived from an earlier language called “B” (Basic Co..
This course teaches engineering students how to program in C. I gave this course for several years in the framework of the "Advanced Technology Higher Education Network" / SOCRATES program.
It is a very simple and easy language, C language is mainly used for develop desktop based application. All other programming languages were derived directly or indirectly from C programming concepts. This language have following features;
http://www.tutorial4us.com/cprogramming/c-features
This presentation is about -
embedded system programming,
What are device drivers?,
Types of device driver,
Recognizing device drivers,
Character Device Drivers,
Features of kernel programming,
This session reviews some key features of the C++ language that are of interest to the embedded software developer. Also, some language features and implementation details that may be troublesome are highlighted and explained.
* Memory types (RAM, ROM, EEPROM, etc).
* Program memory segments.
* Static vs. Dynamic memory allocation.
* Static vs. Dynamic linking.
* Function call with respect to stack, i/p, o/p and i/o parameters and return value.
* Functions types (Synch. vs. ASynch, Reentrant vs. non-Reentrant, Recursive, Inline function vs. function-like macro).
* What are Embedded Systems?
* C for Embedded Systems vs. Embedded C.
* Code Compilation process.
* Error types.
* Code Compilation using command line.
structure of c program. everything about the structure is in this ppt...................................................................viearhgviuehdrgbvkejfsdbvaerhbgf;oiweHFGIO;WENEGV;KLADFN;OVIBNA;OINVO;IRANV;OINDF;LNVOIASRDNGVIOERNAVB EOANGVV ERNGOEWN
Download this Presentation for free from www.ecti.co.in/downloads.html
No SIGN UP REQUIRED.
C Programming Training PPTs / PDFs for free.
Download free C Programming study material. Learn C Programming for free in 2 hours.
This is a presentation on C language. Brief description on C language
Topics Covered
What is C
Header files in C
What is main function in c
Basic Structure of C
Keywords & Identifiers
Data Types & Variable Declaration in C Includes | Format Specifier | Memory Size
Input in C (printf() scanf() function)
Operators in C: Asthmatics,Increment Decrement, Relational, Logical operators
Sample Exercise
LinkedIn: https://www.linkedin.com/in/shamsulhusainansari/
GitHub: https://github.com/shamsulhusainansari
The C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system.
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
The Earth System Grid Federation (ESGF) is a global network of data servers that archives and distributes the planet’s largest collection of Earth system model output for thousands of climate and environmental scientists worldwide. Many of these petabyte-scale data archives are located in proximity to large high-performance computing (HPC) or cloud computing resources, but the primary workflow for data users consists of transferring data, and applying computations on a different system. As a part of the ESGF 2.0 US project (funded by the United States Department of Energy Office of Science), we developed pre-defined data workflows, which can be run on-demand, capable of applying many data reduction and data analysis to the large ESGF data archives, transferring only the resultant analysis (ex. visualizations, smaller data files). In this talk, we will showcase a few of these workflows, highlighting how Globus Flows can be used for petabyte-scale climate analysis.
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
The U.S. Geological Survey (USGS) has made substantial investments in meeting evolving scientific, technical, and policy driven demands on storing, managing, and delivering data. As these demands continue to grow in complexity and scale, the USGS must continue to explore innovative solutions to improve its management, curation, sharing, delivering, and preservation approaches for large-scale research data. Supporting these needs, the USGS has partnered with the University of Chicago-Globus to research and develop advanced repository components and workflows leveraging its current investment in Globus. The primary outcome of this partnership includes the development of a prototype enterprise repository, driven by USGS Data Release requirements, through exploration and implementation of the entire suite of the Globus platform offerings, including Globus Flow, Globus Auth, Globus Transfer, and Globus Search. This presentation will provide insights into this research partnership, introduce the unique requirements and challenges being addressed and provide relevant project progress.
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Mind IT Systems
Healthcare providers often struggle with the complexities of chronic conditions and remote patient monitoring, as each patient requires personalized care and ongoing monitoring. Off-the-shelf solutions may not meet these diverse needs, leading to inefficiencies and gaps in care. It’s here, custom healthcare software offers a tailored solution, ensuring improved care and effectiveness.
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteGoogle
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
👉👉 Click Here To Get More Info 👇👇
https://sumonreview.com/ai-pilot-review/
AI Pilot Review: Key Features
✅Deploy AI expert bots in Any Niche With Just A Click
✅With one keyword, generate complete funnels, websites, landing pages, and more.
✅More than 85 AI features are included in the AI pilot.
✅No setup or configuration; use your voice (like Siri) to do whatever you want.
✅You Can Use AI Pilot To Create your version of AI Pilot And Charge People For It…
✅ZERO Manual Work With AI Pilot. Never write, Design, Or Code Again.
✅ZERO Limits On Features Or Usages
✅Use Our AI-powered Traffic To Get Hundreds Of Customers
✅No Complicated Setup: Get Up And Running In 2 Minutes
✅99.99% Up-Time Guaranteed
✅30 Days Money-Back Guarantee
✅ZERO Upfront Cost
See My Other Reviews Article:
(1) TubeTrivia AI Review: https://sumonreview.com/tubetrivia-ai-review
(2) SocioWave Review: https://sumonreview.com/sociowave-review
(3) AI Partner & Profit Review: https://sumonreview.com/ai-partner-profit-review
(4) AI Ebook Suite Review: https://sumonreview.com/ai-ebook-suite-review
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
Even though at surface level ‘java.lang.OutOfMemoryError’ appears as one single error; underlyingly there are 9 types of OutOfMemoryError. Each type of OutOfMemoryError has different causes, diagnosis approaches and solutions. This session equips you with the knowledge, tools, and techniques needed to troubleshoot and conquer OutOfMemoryError in all its forms, ensuring smoother, more efficient Java applications.
Navigating the Metaverse: A Journey into Virtual Evolution"Donna Lenk
Join us for an exploration of the Metaverse's evolution, where innovation meets imagination. Discover new dimensions of virtual events, engage with thought-provoking discussions, and witness the transformative power of digital realms."
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Anthony Dahanne
Les Buildpacks existent depuis plus de 10 ans ! D’abord, ils étaient utilisés pour détecter et construire une application avant de la déployer sur certains PaaS. Ensuite, nous avons pu créer des images Docker (OCI) avec leur dernière génération, les Cloud Native Buildpacks (CNCF en incubation). Sont-ils une bonne alternative au Dockerfile ? Que sont les buildpacks Paketo ? Quelles communautés les soutiennent et comment ?
Venez le découvrir lors de cette session ignite
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamtakuyayamamoto1800
In this slide, we show the simulation example and the way to compile this solver.
In this solver, the Helmholtz equation can be solved by helmholtzFoam. Also, the Helmholtz equation with uniformly dispersed bubbles can be simulated by helmholtzBubbleFoam.
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
Traditional software testing methods are being challenged in retail, where customer expectations and technological advancements continually shape the landscape. Enter generative AI—a transformative subset of artificial intelligence technologies poised to revolutionize software testing.
First Steps with Globus Compute Multi-User EndpointsGlobus
In this presentation we will share our experiences around getting started with the Globus Compute multi-user endpoint. Working with the Pharmacology group at the University of Auckland, we have previously written an application using Globus Compute that can offload computationally expensive steps in the researcher's workflows, which they wish to manage from their familiar Windows environments, onto the NeSI (New Zealand eScience Infrastructure) cluster. Some of the challenges we have encountered were that each researcher had to set up and manage their own single-user globus compute endpoint and that the workloads had varying resource requirements (CPUs, memory and wall time) between different runs. We hope that the multi-user endpoint will help to address these challenges and share an update on our progress here.
Check out the webinar slides to learn more about how XfilesPro transforms Salesforce document management by leveraging its world-class applications. For more details, please connect with sales@xfilespro.com
If you want to watch the on-demand webinar, please click here: https://www.xfilespro.com/webinars/salesforce-document-management-2-0-smarter-faster-better/
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
Large Language Models (LLMs) are currently the center of attention in the tech world, particularly for their potential to advance research. In this presentation, we'll explore a straightforward and effective method for quickly initiating inference runs on supercomputers using the vLLM tool with Globus Compute, specifically on the Polaris system at ALCF. We'll begin by briefly discussing the popularity and applications of LLMs in various fields. Following this, we will introduce the vLLM tool, and explain how it integrates with Globus Compute to efficiently manage LLM operations on Polaris. Attendees will learn the practical aspects of setting up and remotely triggering LLMs from local machines, focusing on ease of use and efficiency. This talk is ideal for researchers and practitioners looking to leverage the power of LLMs in their work, offering a clear guide to harnessing supercomputing resources for quick and effective LLM inference.
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I didn't get rich from it but it did have 63K downloads (powered possible tens of thousands of websites).
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus
As part of the DOE Integrated Research Infrastructure (IRI) program, NERSC at Lawrence Berkeley National Lab and ALCF at Argonne National Lab are working closely with General Atomics on accelerating the computing requirements of the DIII-D experiment. As part of the work the team is investigating ways to speedup the time to solution for many different parts of the DIII-D workflow including how they run jobs on HPC systems. One of these routes is looking at Globus Compute as a way to replace the current method for managing tasks and we describe a brief proof of concept showing how Globus Compute could help to schedule jobs and be a tool to connect compute at different facilities.
Listen to the keynote address and hear about the latest developments from Rachana Ananthakrishnan and Ian Foster who review the updates to the Globus Platform and Service, and the relevance of Globus to the scientific community as an automation platform to accelerate scientific discovery.
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfJay Das
With the advent of artificial intelligence or AI tools, project management processes are undergoing a transformative shift. By using tools like ChatGPT, and Bard organizations can empower their leaders and managers to plan, execute, and monitor projects more effectively.
How Recreation Management Software Can Streamline Your Operations.pptxwottaspaceseo
Recreation management software streamlines operations by automating key tasks such as scheduling, registration, and payment processing, reducing manual workload and errors. It provides centralized management of facilities, classes, and events, ensuring efficient resource allocation and facility usage. The software offers user-friendly online portals for easy access to bookings and program information, enhancing customer experience. Real-time reporting and data analytics deliver insights into attendance and preferences, aiding in strategic decision-making. Additionally, effective communication tools keep participants and staff informed with timely updates. Overall, recreation management software enhances efficiency, improves service delivery, and boosts customer satisfaction.
How to Position Your Globus Data Portal for Success Ten Good PracticesGlobus
Science gateways allow science and engineering communities to access shared data, software, computing services, and instruments. Science gateways have gained a lot of traction in the last twenty years, as evidenced by projects such as the Science Gateways Community Institute (SGCI) and the Center of Excellence on Science Gateways (SGX3) in the US, The Australian Research Data Commons (ARDC) and its platforms in Australia, and the projects around Virtual Research Environments in Europe. A few mature frameworks have evolved with their different strengths and foci and have been taken up by a larger community such as the Globus Data Portal, Hubzero, Tapis, and Galaxy. However, even when gateways are built on successful frameworks, they continue to face the challenges of ongoing maintenance costs and how to meet the ever-expanding needs of the community they serve with enhanced features. It is not uncommon that gateways with compelling use cases are nonetheless unable to get past the prototype phase and become a full production service, or if they do, they don't survive more than a couple of years. While there is no guaranteed pathway to success, it seems likely that for any gateway there is a need for a strong community and/or solid funding streams to create and sustain its success. With over twenty years of examples to draw from, this presentation goes into detail for ten factors common to successful and enduring gateways that effectively serve as best practices for any new or developing gateway.
2. Embedded systems
qComputers used as a part of larger system
-- that usually doesn’t look like a computer
-- that usually controls physical devices
qOften reliability is critical
--“Critical” as in “if system fails someone might die”
qOften resources (memory, processor capacity) are limited
qOften real-time response is essential
4. üWhat are the difference between microcontroller and microprocessor ?
üWhat is an N-bit CPU/microcontroller/microprocessor ?
üHow does an embedded program run ?
üWhat is Hard real time and soft real time embedded systems ?
üWhy is design of embedded system is difficult ?
üFlow chart Vs Pseudo code
7. Why do we use C……?
C has now become a widely used professional language for various reasons.
•Easy to learn
•Structured language
•It produces efficient programs.
•It can handle low-level activities.
•It can be compiled on a variety of computers.
C suit for developing
OSs,
System level programming,
Embedded Systems(including micro-controllers such as PIC, ARM, and MP),
RTOS,
Compilers,
website programming
libraries to other languages
8. C programming Features cont...
Powerful programming language:
C is very efficient and powerful programming language, which provides various data
types, functions, pointers, control and loop control statements, & it is best used for data
structures and developing system software.
Efficient use of pointers, pointers has direct access to memory.
Bit manipulation:
C program can be manipulated using bits. We can perform different operations at bit
level. We can manage memory at bit level.(for ex: in structures)
High Level Features :
It is more User friendly as compare to Previous languages. Previous languages such as
BCPL,Pascal and other programming languages never provide such great features to
manage data. Previous languages have there pros and cons but C Programming collected
all useful features of previous languages thus C become more effective language.
9. Advantages (or) features of C programming language
C is the most popular programming language, C has many advantages:
Modularity:
Modularity is one of the important characteristics of C. we can split the C program in to
number of modules instead of repeating same logic statements(sequentially). It allows
reusability of modules.
Middle level language:
As a middle level language C combines advantages of both high and low level
language. (array, pointers, etc.)
General purpose programming language: C can be used to implement any kind of
applications such as maths oriented, graphics, business oriented applications.
Portability: We can compile or execute C programming in any operating system
(windows, dos, unix).
10. structure of C a program
#include<stdio.h> /* Header File */
main () /* starting function */
{ /* start of program */
--------
Statements;
--------
Return;
}
11. Example C program
Ex:
/* Hello world Program*/
#include <stdio.h>
int main()
{
printf (“Hello worldn”);
return 0;
}
13. Type the following command to verify that gcc is installed:
$ which gcc
Output:
/usr/bin/gcc
Find out version of gcc:
$ gcc --version
Output:
gcc (GCC) 4.0.3 20060212 (prerelease) (Debian 4.0.2-9) Copyright (C) 2006 Free
Software Foundation, Inc. This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
14. Step by step compilation commands:
-E preprocess only, do not compile, assemble or link.
-S compile only, do not assemble or link.
-C compile and assemble, but do not link
-O Place the output in to file
$gcc –E hello.c –o hello.i
$gcc –S hello.i –o hello.s
$gcc –C hello.s –o hello.o
$./hello.o
15. Format Specifiers
There are many format specifiers defined in C. Take a look at the following list:
%i or %d int
%c char
%f float
%lf double
%s string
Note: %lf stands for long float.
16. Let’s take a look at an example of printf formatted output:
#include<stdio.h>
main()
{
int a,b;
float c,d;
a = 15;
b = a / 2;
printf("%dn",b);
printf("%3dn",b);
printf("%03dn",b);
c = 15.3;
d = c / 3;
printf("%3.2fn",d);
}
20. Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to
2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
Integer Types
Following table gives you details about standard integer types with its storage
sizes and value ranges:
21. Floating-Point Types
Following table gives you details about standard floating-point types with storage
sizes and value ranges and their precision:
Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places
22. C program to Find Maximum and minimum range of Float data type
#include <stdio.h>
#include <float.h>
int main()
{
printf("Storage size for float : %d n", sizeof(float));
printf("Minimum float positive value: %En", FLT_MIN );
printf("Maximum float positive value: %En", FLT_MAX );
printf("Precision value: %dn", FLT_DIG );
return 0;
}
23. Identifiers in C language:
•Each program elements in a C program are given a name called identifiers.
•Names given to identify Variables, functions and arrays are examples for identifiers.
Keywords in C language:
•Keywords are pre-defined words in a C compiler.
•Each keyword is meant to perform a specific function in a C program.
•Since keywords are referred names for compiler, they can’t be used as variable name
•C language supports 32 keywords
24. Variables in C
C variable is a named location in a memory where a program can
manipulate the data. This location is used to hold the value of the variable.
The value of the C variable may get change in the program.
C variable might be belonging to any of the data type like int, float, char etc.
25. Rules for Constructing Variable Names
A Variable name consists of any combination of alphabets, digits and
underscores.
Some compiler allows variable names whole length could be up to 247
characters. Still it would be safer to stick to the rule of 31 characters.
The first character of the variable name must either be alphabet or underscore,
It should not start with the digit.
No commas and blanks are allowed in the variable name
No special symbols other than underscore are allowed in the variable name
26. C tokens:
•C tokens are the basic buildings blocks in C language which are constructed together to
write a C program.
•Each and every smallest individual units in a C program are known as C tokens.
•C tokens are of six types. They are,
1.Keywords (eg: int, while),
3.Identifiers (eg: main, total),
5.Constants (eg: 10, 20),
7.Strings (eg: “total”, “hello”),
9.Special symbols (eg: (), {}),
11.Operators (eg: +, /,-,*)
27. C tokens example program:
int main()
{
int x, y, total;
x=10, y=20;
total=x+y;
printf(“total=%dn”,total);
}
where,
main – identifier
{,}, (,) – delimiter
int – keyword
x, y, total – identifier
main, {, }, (, ), int, x, y, total – tokens
29. Operators cotnd....
Conditional operator
Also called ternary operator or ?: operator
Ex: Use a conditional operator to find whether number you entered is odd or
even
Special operators
-Sizeof(), & and * pointer operators
Comma operator
-Comma as operator and as separator.
30. Operator precedence and Associativity
Operator precedence determines the grouping of terms in an expression.
This affects how an expression is evaluated.
Category Operator Associativity
Postfix () [] -> . ++ - - Left to right
Unary + - ! ~ ++ - - (type)* & sizeof Right to left
Multiplicative * / % Left to right
Additive + - Left to right
Shift << >> Left to right
Relational < <= > >= Left to right
Equality == != Left to right
31. Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %=>>= <<= &= ^=
|=
Right to left
Comma , Left to right
32. /* c program to illustrate mathematical operations.*/
# include <stdio.h>
int main()
{
int i;
i = 5;
printf("The Value of i is : %d", i);
i = i + 5;
printf("nThe Value of i is : %d", i);
i = i - 2;
printf("nThe Value of i is : %d", i);
i = i * 2;
printf("nThe Value of i is : %d", i);
i = i / 4;
printf("nThe Value of i is : %d", i);
i++;
printf("nThe Value of i is : %d", i);
i++;
printf("nThe Value of i is : %d", i);
i --;
printf("nThe Value of i is : %d", i);
return(0) ;
}
33. Constants in C:
•C Constants are also like normal variables. But, only difference is, their values
can not be modified by the program once they are defined.
•Constants refer to fixed values.
•Constants may be belonging to any of the data type.
S.no Constant type data type Example
1 Integer constants int
unsigned int
long int
long long int
53, 762, -478 etc
5000u, 1000U etc
483,647
2,147,483,680
2 Real or Floating point constants float
doule
10.456789
600.123456789
3 Octal constant int 013 /* starts with 0 */
4 Hexadecimal constant int 0×90 /* starts with 0x */
5 character constants char ‘A’ , ‘B’, ‘C’
6 string constants char “ABCD” , “Hai”
34. Defining Constants
There are two simple ways in C to define constants:
-Using #define preprocessor.
-Using const keyword.
35. /* Example program using #define preprocessor */
#include <stdio.h>
#define LENGTH 10
#define WIDTH 5
#define NEWLINE 'n'
int main()
{
int area;
area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);
return 0;
}
36. /* defining constants using const */
#include <stdio.h>
int main()
{
const int LENGTH = 10;
const int WIDTH = 5;
const char NEWLINE = 'n';
int area;
area = LENGTH * WIDTH;
printf("value of area : %d", area);
printf("%c", NEWLINE);
return 0;
}
37. #include <stdio.h>
int main()
{
char ch = 'A';
char str[20] = "fresh2refresh.com";
float flt = 10.234;
int no = 150;
double dbl = 20.123456;
printf("Character is %c n", ch);
printf("String is %s n" , str);
printf("Float value is %f n", flt);
printf("Integer value is %dn" , no);
printf("Double value is %lf n", dbl);
printf("Octal value is %o n", no);
printf("Hexadecimal value is %x n", no);
return 0;
}
38. #include <stdio.h>
int main()
{
char ch;
char str[100];
printf("Enter any character n");
scanf("%c", &ch);
printf("Entered character is %c n", ch);
printf("Enter any string ( upto 100 character ) n");
scanf("%s", &str);
printf("Entered string is %s n", str);
}
39. Bit wise operators in C:
These operators are used to perform bit operations. Decimal values are converted
into binary values which are the sequence of bits and bit wise operators work on
these bits.
Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~ (bitwise OR),
^ (XOR), << (left shift) and >> (right shift).
x y x|y x & y x ^ y Operator_symbol Operator_name
& Bitwise_AND
0 0 0 0 0 | BitwiseOR
0 1 1 0 1
~ Bitwise_NOT
1 0 1 0 1
^ XOR1 1 1 1 0
<< Left Shift
>> Right Shift
Truth table for bitwise operator bitwise operator
40. #include <stdio.h>
int main()
{
int m=40,n=80,AND_opr,OR_opr,XOR_opr,NOT_opr ;
AND_opr = (m&n);
OR_opr = (m|n);
NOT_opr = (~m);
XOR_opr = (m^n);
printf("AND_opr value = %dn",AND_opr );
printf("OR_opr value = %dn",OR_opr );
printf("NOT_opr value = %dn",NOT_opr );
printf("XOR_opr value = %dn",XOR_opr );
printf("left_shift value = %dn", m << 1);
printf("right_shift value = %dn", m >> 1);
}
41. Conditional or ternary operators in C:
Conditional operators return one value if condition is true and returns another
value is condition is false.
This operator is also called as ternary operator.
Syntax : (Condition? true_value: false_value);
Example : (A > 100 ? 0 : 1);
In above example, if A is greater than 100, 0 is returned else 1 is returned. This is
equal to if else conditional statements.
42. C provides two types of flow control
●Branching
●Looping
●
Branching
1. If Statement
2. The If else Statement
3. Compound Relational tests
4. Nested if Statement
5. Switch Statement
Loop control statements in C
1. for
2. while
3. do-while
43. If statement
if(condition)
{
statement;
}
If else statement
If(condition)
Program statement1
else
program statement 2
Compound relational test
a) if (condition1 && condition2 && condition3)
b) if (condition1 || condition2 || condition3)
44. Nested if statement
if (condition1)
if (condition2)
statement-1;
else
statement-2;
else
statement-3;
45. Switch statement
switch( expression )
{
case constant-expression1: statements1;
break;
case constant-expression2: statements2;
break;
case constant-expression3: statements3;
break;
default : statements4;
}
// Note: Expression used in switch must be integral type (char, int, enum).
Default can be placed anywhere in the program.
Statements written above case are never executed.
Two case labels cannot have same value.
46. while ( expression )
{
Single statement or Block of statements;
}
for( expression1; expression2; expression3)
{
Single statement or Block of statements;
}
do
{
Single statement or Block of statements;
} while(expression);
48. //program to demonstrate the working of continue statement in C
programming
# include <stdio.h>
int main(){
int i,num,product;
for(i=1,product=1;i<=4;++i)
{
printf("Enter num%d:",i);
scanf("%d",&num);
if(num==0)
continue; / *In this program, when num equals to zero, it skips the
statement product*=num and continue the loop. */
product*=num;
}
printf ("product=%d“,product);
return 0;
}
49. -Prog to print numbers from 1 to 10 skipping 5 using continue.
-Prog to check, if number entered is equal to 10, less than 10 or greater than 10.
-Write a program to find greatest of 2 numbers.
-Write a program to find greatest of 3 numbers.
-Write a program to generate counts from 1 to 20 using while and for loop.
-Prog to reverse a integer
-Prog to calculate power of a number
-Prog to implement a simple calculator
-Prog to print prime numbers from 1 to 100.
-Prog to find number entered is palindrome or not
-Prog to find factorial of a number
-Prog to find if a given bit is set to one or not
-For a given binary number find equivalent decimal value
-Prog to count number of bits set to ‘0’ in a binary value
-Prog to check if all bits of a given integer is one
-Prog to check if a given integer is power of two
-Prog to swap two numbers using bitwise operator
-Prog to find sum of odd and even numbers from 1 to N
-Prog to read 4 integers and find average of last two numbers
-Prog to read number of month and display month
50. Scope Rules
A scope in any programming is a region of the program where a defined
variable can have its existence and beyond that variable can not be accessed.
There are three places where variables can be declared in C programming
language:
•Inside a function or a block which is called local variables,
•Outside of all functions which is called global variables.
•In the definition of function parameters which is called formal parameters.
51. Local Variables
Variables that are declared inside a function or block are called local variables.
They can be used only by statements that are inside that function or block of code.
Local variables are not known to functions outside their own.
#include <stdio.h>
int main ()
{
int a, b; /* local variable declaration */
int c;
A = 10; /* actual initialization */
b = 20;
c = a + b;
printf ("value of a = %d, b = %d and c = %dn",
a, b, c);
return 0;
}
52. Local Variables
Variables that are declared inside a function or block are called local variables.
They can be used only by statements that are inside that function or block of code.
Local variables are not known to functions outside their own.
#include <stdio.h>
int main ()
{
int a, b; /* local variable declaration */
int c;
A = 10; /* actual initialization */
b = 20;
c = a + b;
printf ("value of a = %d, b = %d and c = %dn",
a, b, c);
return 0;
}
53. Global Variables
Global variables are defined outside of a function, usually on top of the
program. The global variables will hold their value throughout the lifetime of your
program and they can be accessed inside any of the functions defined for the
program.
#include <stdio.h>
int g; /* global variable declaration */
int main ()
{
int a, b; /* local variable declaration */
a = 10; /* actual initialization */
b = 20;
g = a + b;
printf ("value of a = %d, b = %d and g = %dn", a, b, g);
return 0;
}
54. Formal Parameters
Function parameters, formal parameters, are treated as local variables with-in that
function and they will take preference over the global variables.
#include <stdio.h>
int a = 20; /* global variable declaration */
int main ()
{
int a = 10; /* local variable declaration in main function */
int b = 20;
int c = 0;
printf ("value of a in main() = %dn", a);
c = sum( a, b);
printf ("value of c in main() = %dn", c);
return 0;
}
int sum(int a, int b) /* function to add two integers */
{
printf ("value of a in sum() = %dn", a);
printf ("value of b in sum() = %dn", b);
return a + b; }
55. Initializing Local and Global Variables
When a local variable is defined, it is not initialized by the system, you must
initialize it yourself. Global variables are initialized automatically by the system
when you define them as follows:
Data Type Initial Default Value
int 0
char '0'
float 0
double 0
pointer NULL
56. Storage class specifiers in C
There are 4 storage class specifiers available in C language. They are,
• auto
• extern
• static
• register
57. --Find output of following program
#include<stdio.h>
void increment(void);
int main()
{
increment();
increment();
increment();
increment();
return 0;
}
void increment(void)
{
static int i = 0 ;
printf ( "%d ", i ) ;
i++;
}
58. Memory Layout of C programs
A typical memory representation of C program consists of following sections.
1. Text segment
2. Initialized data segment
3. Uninitialized data segment
4. Stack
5. Heap
59. 1. Text Segment:
A text segment , also known as a code segment or simply as text, is one of the
sections of a program in an object file or in memory, which contains executable
instructions.
2. Initialized Data Segment:
Initialized data segment, usually called simply the Data Segment. A data segment is
a portion of virtual address space of a program, which contains the global variables
and static variables that are initialized by the programmer.
Note that, data segment is not read-only, since the values of the variables can be
altered at run time.
60. 2. Initialized Data Segment:
This segment can be further classified into initialized read-only area and initialized
read-write area.
For instance the global string defined by char s[] = “hello world” in C and a C
statement like int debug=1 outside the main (i.e. global) would be stored in
initialized read-write area. And a global C statement like const char* string = “hello
world” makes the string literal “hello world” to be stored in initialized read-only
area and the character pointer variable string in initialized read-write area.
Ex: static int i = 10 will be stored in data segment and global int i = 10 will also be
stored in data segment
61. 3. Uninitialized Data Segment:
Uninitialized data segment, often called the “bss” segment, named after an ancient
assembler operator that stood for “block started by symbol.” Data in this segment is
initialized by the kernel to arithmetic 0 before the program starts executing
uninitialized data starts at the end of the data segment and contains all global
variables and static variables that are initialized to zero or do not have explicit
initialization in source code.
For instance a variable declared static int i; would be contained in the BSS segment.
For instance a global variable declared int j; would be contained in the BSS segment
62. 4. Stack:
The stack area traditionally adjoined the heap area and grew the opposite direction;
when the stack pointer met the heap pointer, free memory was exhausted. (With
modern large address spaces and virtual memory techniques they may be placed
almost anywhere, but they still typically grow opposite directions.
Stack, where automatic variables are stored, along with information that is saved
each time a function is called. Each time a function is called, the address of where
to return to and certain information about the caller’s environment, such as some
of the machine registers, are saved on the stack. The newly called function then
allocates room on the stack for its automatic and temporary variables. This is how
recursive functions in C can work. Each time a recursive function calls itself, a new
stack frame is used, so one set of variables doesn’t interfere with the variables from
another instance of the function.
63. 5. Heap:
Heap is the segment where dynamic memory allocation usually takes place.
The heap area begins at the end of the BSS segment and grows to larger addresses
from there.The Heap area is managed by malloc, realloc, and free,
64. Arrays
C Array is a collection of variables belongings to the same data type. You can store
group of data of same data type in an array.
•Array might be belonging to any of the data types
•Array size must be a constant value.
•Always, Contiguous (adjacent) memory locations are used to store array elements in
memory.
•It is a best practice to initialize an array to zero or null while declaring, if we don’t
assign any values to array.
•Array can be single dimensional or multidimensional
65. Declaring single dimensional array :
Syntax: data_type arr_name [size];
int a[10]; // integer array
char b[10]; // character array i.e. string
int arr[ ]={3,6,8,9,3,};
#include<stdio.h>
int main()
{
int i;
int arr[5] = {10,20,30,40,50};
for (i=0;i<5;i++)
{
printf("value of arr[%d] is %d n", i, arr[i]);
}
}
66. Multidimensional array declaration
Syntax: data_type arr_name [no_of_rows][no_of_columns];
int arr [2][2]={1, 2, 3, 4};
#include<stdio.h>
int main()
{
int i,j;
int arr[2][2] = {10,20,30,40};
for (i=0;i<2;i++)
{
for (j=0;j<2;j++)
{
printf("value of arr[%d] [%d] : %dn",i,j,arr[i][j]);
}}}
67. -- prog to Add elements of an array at odd position.
-- Prog to find intersection of 3 arrays.
68. Functions:
The general form of a function definition in C programming language is as follows:
Syntax: return_type function_name ( [parameter list] )
{
// body of the function
}
Function Declarations:
A function declaration tells the compiler about a function name and how to call the function. A function declaration has
the following parts:
return_type function_name( parameter list );
Ex: int max(int num1, int num2);
Ex: int max(int, int); // is also valid declaration
Calling a function in C
function_name( [arg1, ... ] );
69. Calling a function:
•Call by value
•Call by reference
Different types of function calling in c programming
•Function with no arguments and no return value
•Function with no arguments and return value
•Function with arguments but no return value
•Function with arguments and return value.
70. /*Program using function call by value*/
void swap(int x, int y)
{
int z;
z = x;
x = y;
y = z;
printf("Swapped values are a = %d and b = %d", x, y);
}
void main()
{
int a = 7, b = 4;
printf("Original values are a = %d and b = %d", a, b);
swap(a, b);
printf("The values after swap are a = %d and b = %d", a,
b);
}
71. Recursion in C:
A function that calls itself is known as recursive function and this technique is known as recursion in C programming.
/*program to find sum of first n natural numbers using recursion. Note: Positive integers are known as natural
number i.e. 1, 2, 3....n*/
#include <stdio.h>
int sum(int n);
int main()
{
int num,add;
printf("Enter a positive integer:n");
scanf("%d",&num);
add=sum(num);
printf("sum=%d",add);
}
int sum(int n)
{
if(n==0)
return n;
else
return n+sum(n-1); /*self call to function sum() */}
72. Macros in C
All the lines starting with # are processed by preprocessor
1) There is a difference in following two
#include <example.h>
#include “example.h”
2) When we use define for a constant, the preprocessor produces a C program where the defined constant is
searched and matching tokens are replaced with the given expression
3) The macros can take function like arguments, the arguments are not checked for data type.
4) The macro arguments are not evaluated before macro expansion. For example consider the following program
#include <stdio.h>
#define MULTIPLY(a, b) a*b
int main()
{
printf("%d", MULTIPLY(2+3, 3+5));
return 0;
}
73. 6) The tokens passed to macros can be concatenated using operator ## called Token-Pasting operator.
#include <stdio.h>
#define merge(a, b) a##b
int main()
{
printf ("%d ", merge(12, 34));
}
7) A token passed to macro can be converted to a sting literal by using # before it.
#include <stdio.h>
#define message_for(a, b)
printf(#a " and " #b ": We love you!n")
int main(void)
{
message_for(Carole, Debra);
return 0;
}
74. 8) The macros can be written in multiple lines using ‘’. The last line doesn’t need to have ‘’.
#include <stdio.h>
#define PRINT(i, limit) while (i < limit)
{
printf ("GeeksQuiz ");
i++;
}
int main()
{
int i = 0;
PRINT(i, 3);
return 0;
}
9) Find the output of following program
#define square(x) x*x
int main()
{
int x = 36/square(6);
printf("%d", x);
return 0;
}
75. 10) There are some standard macros
#include <stdio.h>
int main()
{
printf("Current File :%sn", __FILE__ );
printf("Current Date :%sn", __DATE__ );
printf("Current Time :%sn", __TIME__ );
printf("Line Number :%dn", __LINE__ );
return 0;
}
11) Other directives in C
a) #if, #elif, #else, #endif
#if constant_expression
#else
#endif
or
#if constant_expression
#elif constant_expression
#endif
76. c) #error
The #error directive will cause the compiler to halt compiling and return with the specified error message.
Syntax:
#error message
Examples:
#ifndef VERSION
#error Version number not specified.
#endif
d) #pragma
#pragma startup function1
#pragma exit function 1
#pragma warning(disable:4700)
#pragma warning(once:4700)
#pragma warning(error:4700)
77. What is the output if following program?
#include<stdio.h>
int main()
{
void v = 0;
printf("%d", v);
return 0;
}
#include<stdio.h>
int main()
{
extern int a;
printf("%dn", a);
return 0;
}
int a=20;
79. Point out errors in following code
#include<stdio.h>
int main()
{
display();
return 0;
}
void display()
{
printf("IndiaBIX.com");
}
#include<stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %dn", j, j);
j++;
}
return 0;
}
80. #include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf("b = %d c = %dn", b, c);
return 0;
}
#include<stdio.h>
int main()
{
int i=1;
for(;;)
{
printf("%dn", i++);
if(i>10)
break;
}
return 0;
}
81. #include<stdio.h>
int main()
{
int a = 5;
switch(a)
{
case 1:
printf("First");
case 2:
printf("Second");
case 3 + 2:
printf("Third");
case 5:
printf("Final");
break;
}
return 0;
}
82. Syntax: Data type *var_name
#include <stdio.h>
int main ()
{
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
printf("Address of var variable: %xn", &var );
printf("Address stored in ip variable: %xn", ip );
printf("Value of *ip variable: %dn", *ip );
return 0;
}
Pointer
A pointer is a variable whose value is the address of another variable, i.e., direct address of the
memory location. Like any variable or constant, you must declare a pointer before you can use it to
store any variable address. The general form of a pointer variable declaration is:
83. Incrementing a Pointer
We prefer using a pointer in our program instead of an array because the variable pointer can be
incremented, unlike the array name which cannot be incremented because it is a constant pointer.
The following program increments the variable pointer to access each succeeding element of the
array:
#include <stdio.h>
const int MAX = 3;
int main ()
{
int var[] = {10, 100, 200};
int i, *ptr;
ptr = var;
for ( i = 0; i < MAX; i++)
{
printf("Address of var[%d] = %un", i, ptr );
printf("Value of var[%d] = %dn", i, *ptr );
ptr++; /* move to the next location */
}
return 0;
}
84. Pointer to Pointer in C
A pointer to a pointer is a form of multiple indirection, or a chain of pointers. Normally, a pointer
contains the address of a variable. When we define a pointer to a pointer, the first pointer contains
the address of the second pointer, which points to the location that contains the actual value as
shown below.
Syntax: int **var_name;
#include <stdio.h>
int main ()
{
int var;
int *ptr;
int **pptr;
var = 3000;
ptr = &var;
pptr = &ptr;
printf("Value of var = %dn", var );
printf("Value available at *ptr = %dn", *ptr );
printf("Value available at **pptr = %dn", **pptr);
return 0;
}
85. Passing pointer to function
#include <stdio.h>
#include <time.h>
void getSeconds(unsigned long *par);
int main ()
{
unsigned long sec;
getSeconds( &sec );
/* print the actual value */
printf("Number of seconds: %ldn", sec );
return 0;
}
void getSeconds(unsigned long *par)
{
/* get the current number of seconds */
*par = time( NULL );
return;
}
86. Strings
• C Strings are nothing but array of characters ended with null character (‘0’).
• This null character indicates the end of the string.
• Strings are always enclosed by double quotes. Whereas, character is enclosed by single quotes in C.
Example for C string:
char string[20] = { ‘f’ , ’r’ , ‘e’ , ‘s’ , ‘h’ , ‘2’ , ‘r’ , ‘e’ , ‘f’ , ’r’ , ‘e’ , ‘s’ , ‘h’ , ‘0’}; (or)
char string[20] = “fresh2refresh”; (or)
char string [] = “fresh2refresh”;
char greeting[] = "Hello";
Following is the memory presentation of above defined string in C:
String Presentation in C
88. /*program to reverse a string*/
#include<stdio.h>
#include<string.h>
void main()
{
char str[100],temp;
int i,j=0;
printf("nEnter the string :");
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("nReverse string is :%s",str);
return(0);}
89.
90. String handling functions
Following are some of the useful string handling functions supported by C.
1) strlen()
2) strcpy()
3) strncpy()
4) strcat()
5) strncat()
6) strcmp()
7) strncmp()
8) strcmpi()
9) strncmpi()
strlen()
strlen() function returns the length of the string. strlen() function returns integer value.
char *str = "Learn C Online";
int strLength;
strLength = strlen(str); //strLength contains the length of the string i.e. 14
91. strcpy()
function is used to copy one string to another. The Destination_String should be a variable and
Source_String can either be a string constant or a variable.
Syntax:
strcpy(Destination_String,Source_String);
char *Destination_String;
char *Source_String = "Learn C Online";
strcpy(Destination_String,Source_String);
printf("%s", Destination_String);
92. strncpy()
strncpy() is used to copy only the left most n characters from source to destination. The
Destination_String should be a variable and Source_String can either be a string constant or a
variable.
Syntax:
strncpy(Destination_String, Source_String,no_of_characters);
strcat()
strcat() is used to concatenate two strings.
The Destination_String should be a variable and Source_String can either be a string constant or a
variable.
Syntax:
strcat(Destination_String, Source_String);
char *Destination_String ="Learn ";
char *Source_String = "C Online";
strcat(Destination_String, Source_String);
puts( Destination_String);
93. char *Destination_String="Visit ";
char *Source_String = "Learn C Online is a great site";
strncat(Destination_String, Source_String,14);
puts( Destination_String);
strncat()
strncat() is used to concatenate only the leftmost n characters from source with the destination
string.
The Destination_String should be a variable and Source_String can either be a string constant or a
variable.
Syntax:
strncat(Destination_String, Source_String,no_of_characters);
94. strcmp()
strcmp() function is use two compare two strings. strcmp() function does a case sensitive
comparison between two strings. The Destination_String and Source_String can either be a string
constant or a variable.
Syntax:
int strcmp(string1, string2);
This function returns integer value after comparison.
char *string1 = "Learn C Online";
char *string2 = "Learn C Online";
int ret;
ret=strcmp(string1, string2);
printf("%d",ret);
95. strncmp()
strncmp() is used to compare only left most ‘n’ characters from the strings.
Syntax:
int strncmp(string1, string2,no_of_chars);
This function returns integer value after comparison.
Value returned is 0 if left most ‘n’ characters of two strings are equal.
char *string1 = "Learn C Online is a great site";
char *string2 = "Learn C Online";
int ret;
ret=strncmp(string1, string2,7);
printf("%d",ret);
96. strcmpi()
strcmpi() function is use two compare two strings. strcmp() function does a case insensitive
comparison between two strings. The Destination_String and Source_String can either be a string
constant or a variable.
Syntax:
int strcmpi(string1, string2);
This function returns integer value after comparison.
char *string1 = “Learn C Online”;
char *string2 = “LEARN C ONLINE”;
int ret;
ret=strcmpi(string1, string2);
printf("%d",ret);
97. strncmpi()
strncmpi() is used to compare only left most ‘n’ characters from the strings. strncmpi() function
does a case insensitive comparison.
Syntax:
int strncmpi(string1, string2,no_of_chars);
This function returns integer value after comparison.
char *string1 = "Learn C Online is a great site";
char *string2 = "LEARN C ONLINE";
int ret;
ret=strncmpi(string1, string2,7);
printf("%d",ret);
98. -- Find the difference between int *const ptr and int const *ptr
-- Prog to calc size of float pointer, integer pointer, char pointer.
-- Find the difference between *ptr++ and ++*ptr
-- Swap two numbers using pointer function
-- Prog to reverse a string using pointers
-- Prog to implement all the above string handling functions.
-- Prog to find number of times each letter repeated in a sentence
-- Prog to concatenate two strings without using string.h
-- Prog to find if a given string is palindrome or not
-- Prog to convert string of upper case to lower and lower case to upper
-- Prog to find sum of diagonals of matrix
-- Prog to add two matrices.
-- Prog to find transpose of matrix.
99. Prog to find number of times letter is repeating in string
for(j=0;j<m;j++)
{
for(i=0;i<len;i++)
{
if(string[j]==string[i])
c++;
}
if(c>=2)
{
printf("nnumber of times %c repeating is: %dn",str[j], c);
}
c=0;
}
104. Bubble sort algorithm
#include<stdio.h>
int main(){
int s,temp,i,j,a[20];
printf("Enter total numbers of elements: ");
scanf("%d",&s);
printf("Enter %d elements: ",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
} } }
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
return 0;
105. Bubble sort algorithm
#include<stdio.h>
int main(){
int s,temp,i,j,a[20];
printf("Enter total numbers of elements: ");
scanf("%d",&s);
printf("Enter %d elements: ",s);
for(i=0;i<s;i++)
scanf("%d",&a[i]);
for(i=s-2;i>=0;i--){
for(j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
} } }
printf("After sorting: ");
for(i=0;i<s;i++)
printf(" %d",a[i]);
return 0;
106. Linear search
int main()
{
int array[100], search, c, n;
printf("Enter the number of elements in arrayn");
scanf("%d",&n);
printf("Enter %d integer(s)n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter the number to searchn");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* if required element found */
{
printf("%d is present at location %d.n", search, c+1);
break;
}}
if (c == n)
printf("%d is not present in array.n", search);
return 0;
107. Binary search
#include <stdio.h>
int main()
{
int c, first, last, middle, n, search, array[100];
printf("Enter number of elementsn");
scanf("%d",&n);
printf("Enter %d integersn", n);
for ( c = 0 ; c < n ; c++ )
scanf("%d",&array[c]); // program assumes input numbers are in ascending order.
printf("Enter value to findn");
scanf("%d",&search);
first = 0;
last = n - 1;
middle = (first+last)/2;
108. while( first <= last )
{
if ( array[middle] < search )
first = middle + 1;
else if ( array[middle] == search )
{
printf("%d found at location %d.n", search, middle+1);
break;
}
else
last = middle - 1;
middle = (first + last)/2;
}
if ( first > last )
printf("Not found! %d is not present in the list.n", search);
return 0;
}
109. Structures in C
A structure is a collection of one or more variables, possibly of different
types, grouped together under a single name for convenient handling.
Structures help organize complicated data, particularly in large programs,
because they permit a group of related variables to be treated as a unit instead
of as separate entities.
110. Uses of C structures:
•C Structures can be used to store huge data. Structures act as a database.
•C Structures can be used to send data to the printer.
•C Structures can interact with keyboard and mouse to store the data.
•C Structures can be used in drawing and floppy formatting.
•C Structures can be used to clear output screen contents.
•C Structures can be used to check computer’s memory size etc.
111. #include <stdio.h>
#include <string.h>
struct student
{
int id;
char name[20];
float percentage;
};
int main()
{
struct student record = {0}; //Initializing to null
record.id=1;
strcpy(record.name, "Raju");
record.percentage = 86.5;
printf(" Id is: %d n", record.id);
printf(" Name is: %s n", record.name);
printf(" Percentage is: %f n", record.percentage);
112. /* prog to demonstrate structures in c*/
#include "stdio.h“
void main( )
{
struct
{
char initial; /* last name initial */
int age; /* childs age */
int grade; /* childs grade in school */
} boy, girl;
boy.initial = 'R';
boy.age = 15;
boy.grade = 75;
girl.age = boy.age - 1; /* she is one year younger */
girl.grade = 82;
girl.initial = 'H';
printf("%c is %d years old and got a grade of %dn",girl.initial, girl.age, girl.grade);
printf("%c is %d years old and got a grade of %dn",boy.initial, boy.age, boy.grade);
}
113. Bit Fields
Suppose your C program contains a number of TRUE/FALSE variables grouped in a structur
struct
{
unsigned int widthValidated;
unsigned int heightValidated;
} status;
Without using bit fields it consumes 8 bytes of memory.
114. Bit Fields
Suppose your C program contains a number of TRUE/FALSE variables grouped in a structur
struct
{
unsigned int widthValidated : 1;
unsigned int heightValidated : 1;
} status;
Using using bit fields it consumes 2 bits of memory.
115. Bit Fields
struct
{
unsigned int widthValidated;
unsigned int heightValidated;
} status1;
struct
{
unsigned int widthValidated : 1;
unsigned int heightValidated : 1;
} status2;
int main( )
{
printf( "Memory size occupied by status1 : %dn", sizeof(status1));
printf( "Memory size occupied by status2 : %dn", sizeof(status2));
return 0;
}.
116. Array of structures
main ()
{
struct item
{
char initial;
int id_no;
};
int j;
struct item a[2];
clrscr();
printf ("n Enter Code_no, Pricen ");
for (j=0;j<2;j++)
scanf ("%c %d",&a[j].initial,&a[j].id_no);
printf ("n information you entered are:");
for (j=0;j<2;j++)
printf ("n %c %d",a[j].initial,a[j].id_no);
117. Nesting structures (structure within structure)
#include "stdio.h"
void main( )
{
struct person
{
char name[25];
int age;
char status; /* M = married, S = single */
} ;
struct alldata
{
int grade;
struct person descrip;
char lunch[25];
} student[53];
119. /*another way of nesting structures*/
struct Employee
{
char ename[20];
int ssn;
float salary;
struct date
{
int date;
int month;
int year;
}doj;
}emp = {"Pritesh",1000,1000.50,{22,6,1990}};
120. Pointer to structure
Structure's member through pointer can be used in two ways:
•Referencing pointer to another address to access memory
•Using dynamic memory allocation
121. /*Example program to demonstrate referencing pointer to another address to
access memory*/
#include <stdio.h>
struct name{
int a;
float b;
};
int main(){
struct name *ptr,p;
ptr=&p; /* Referencing pointer to memory address of p */
printf("Enter integer: ");
scanf("%d",&(*ptr).a);
printf("Enter number: ");
scanf("%f",&(*ptr).b);
printf("Displaying: ");
printf("%d%f",(*ptr).a,(*ptr).b);
return 0;}
122. /*Prog to demonstrate pointers to structures using dynamic memory allocation*/
#include <stdio.h>
#include<stdlib.h>
struct name
{
int a;
float b;
char c[30];
};
int main()
{
struct name *ptr;
int i,n;
printf("Enter n: ");
scanf("%d",&n);
ptr=(struct name*)malloc(n*sizeof(struct name));
/* Above statement allocates the memory for n structures with pointer ptr pointing to base address
123. for(i=0;i<n;++i)
{
printf("Enter string, integer and floating number respectively:n");
scanf("%s%d%f",&(ptr+i)->c,&(ptr+i)->a,&(ptr+i)->b);
}
printf("Displaying Infromation:n");
for(i=0;i<n;++i)
printf("%st%dt%.2fn",(ptr+i)->c,(ptr+i)->a,(ptr+i)->b);
return 0;
}
124. Structure padding
In order to align the data in memory, one or more empty bytes (addresses) are
inserted (or left empty) between memory addresses which are allocated for
other structure members while memory allocation. This concept is called
structure padding.
Architecture of a computer processor is such a way that it can read 1 word (4
byte in 32 bit processor) from memory at a time.
To make use of this advantage of processor, data are always aligned as 4 bytes
package which leads to insert empty addresses between other member’s
address.
Because of this structure padding concept in C, size of the structure is always
not same as what we think.
126. int main()
{
int i;
struct student record1 = {1, 2, 'A', 'B', 90.5};
printf("size of structure in bytes : %dn", sizeof(record1));
printf("nAddress of id1 = %u", &record1.id1 );
printf("nAddress of id2 = %u", &record1.id2 );
printf("nAddress of a = %u", &record1.a );
printf("nAddress of b = %u", &record1.b );
printf("nAddress of percentage = %u",&record1.percentage);
return 0;
}
127. How to avoid structure padding in C?
•#pragma pack ( 1 ) directive can be used for arranging memory for structure
members very next to the end of other structure members.
•VC++ supports this feature. But, some compilers such as Turbo C/C++ does
not support this feature.
•Please check the below program where there will be no addresses (bytes) left
empty because of structure padding.
128. Union
•C Union is also like structure, i.e. collection of different data types which are
grouped together. Each element in a union is called member.
•Union and structure in C are same in concepts, except allocating memory for their
members.
•Structure allocates storage space for all its members separately.
•Whereas, Union allocates one common storage space for all its members
129. #include <stdio.h>
#include <string.h>
union student
{
char name[20];
char subject[20];
float percentage;
};
int main()
{
union student record1;
union student record2;
// assigning values to record1 union variable
strcpy(record1.name, "Raju");
strcpy(record1.subject, "Maths");
record1.percentage = 86.50;
printf("Union record1 values examplen");
135. Dynamic memory allocation in C:
The process of allocating memory during program execution is called
dynamic memory allocation.
Dynamic memory allocation functions in C:
C language offers 4 dynamic memory allocation functions. They are,
1) malloc()
2) calloc()
3) realloc()
4) free()
137. 1. malloc() function in C:
•malloc () function is used to allocate space in memory during the execution of
the program.
•malloc () does not initialize the memory allocated during execution. It carries
garbage value.
•malloc () function returns null pointer if it couldn’t able to allocate requested
amount of memory.
139. 2. calloc() function in C:
calloc () function is also like malloc () function. But calloc () initializes the
allocated memory to zero. But, malloc() doesn’t.
141. 3. realloc() function in C:
•realloc () function modifies the allocated memory size by malloc () and calloc ()
functions to new size.
•If enough space doesn’t exist in memory of current block to extend, new block is
allocated for the full size of reallocation, then copies the existing data to new
block and then frees the old block.
4. free() function in C:
free () function frees the allocated memory by malloc (), calloc (), realloc ()
functions and returns the memory to the system.
143. typedef
Typedef is a keyword that is used to give a new symbolic name for the existing
name in a C program. This is same like defining alias for the commands.
144. Consider the below structure.
struct student
{
int mark [2];
char name [10];
float average;
}
Variable for the above structure can be declared in two ways.
1st way :
struct student record; /* for normal variable */
struct student *record; /* for pointer variable */
2nd way :
typedef struct student status;
145. An alternative way for structure declaration using typedef in C:
typedef struct student
{
int mark [2];
char name [10];
float average;
} status;
To declare structure variable, we can use the below statements.
status record1; /* record 1 is structure variable */
status record2; /* record 2 is structure variable */
146. #include <stdio.h>
#include <string.h>
typedef struct student // Structure using typedef:
{
int id;
char name[20];
float percentage;
} status;
int main()
{
status record;
record.id=1;
strcpy(record.name, "Raju");
record.percentage = 86.5;
printf(" Id is: %d n", record.id);
printf(" Name is: %s n", record.name);
printf(" Percentage is: %f n", record.percentage);
147. Another example program for C typedef:
#include <stdio.h>
#include <limits.h>
int main()
{
typedef long long int LLI;
printf("Storage size for long long int data type : %ld n", sizeof(LLI));
return 0;
}
148. Stack in C
•Stack is a specialized data storage structure (Abstract data type). Unlike, arrays
access of elements in a stack is restricted.
•
•It has two main functions push and pop. Insertion in a stack is done using push
function and removal from a stack is done using pop function.
•
•Stack allows access to only the last element inserted hence, an item can be
inserted or removed from the stack from one end called the top of the stack. It is
therefore, also called Last-In-First-Out (LIFO) list.
149.
150. Applications of stack:
•Balancing of symbols
•
•Infix to Postfix/Prefix conversion
•
•Redo-undo features at many places like editors, photoshop.
•
•Forward and backward feature in web browsers
151. /*Example illustrating stack operation in c*/
#include <stdio.h>
#include <conio.h>
#define MAXSIZE 5
struct stack /* Structure definition for stack */
{
int stk[MAXSIZE];
int top;
};
typedef struct stack STACK;
STACK s;
/* Function declaration/Prototype*/
void push (void);
int pop(void);
void display (void);
152. void main ()
{
int choice;
int option = 1;
clrscr ();
s.top=-1;
printf ("STACK OPERATIONn");
while (option)
{
printf ("------------------------------------------n");
printf (" 1 --> PUSH n");
printf (" 2 --> POP n");
printf (" 3 --> DISPLAY n");
printf (" 4 --> EXIT n");
printf ("------------------------------------------n");
printf ("Enter your choicen");
scanf ("%d", &choice);
153. switch (choice)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4: return;
}
fflush (stdin);
printf ("Do you want to continue(Type 0 or 1)?n");
scanf ("%d", &option);
}
}
154. /*Function to add an element to the stack*/
void push ()
{ int num;
if (s.top == (MAXSIZE - 1))
{
printf ("Stack is Fulln");
return;
}
else
{
printf ("Enter the element to be pushedn");
scanf ("%d", &num);
s.top = s.top + 1;
s.stk[s.top] = num;
}
return;
}
155. /*Function to delete an element from the stack*/
int pop ()
{
int num;
if (s.top == - 1)
{
printf ("Stack is Emptyn");
return (s.top);
}
else
{
num = s.stk[s.top];
printf ("poped element is = %dn", s.stk[s.top]);
s.top = s.top - 1;
}
return(num);
}
156. /*Function to display the status of the stack*/
void display ()
{
int i;
if (s.top == -1)
{
printf ("Stack is emptyn");
return;
}
else
{
printf ("nThe status of the stack isn");
for (i = s.top; i >= 0; i--)
printf ("%dn", s.stk[i]);
}
printf ("n");
}
157. •Queue is a data structure which works as FIFO principle. FIFO means “First in First
out”, i.e the element which we have inserted first will be deleted first and the
element that we have inserted last will be deleted last.
•
•You can have c program to implement queue using array, using stack and using
linked list. Two variables are used to implement queue, i.e “rear” and “front”.
Insertion will be done at rear side and deletion will be performed at front side.
Figure below will show you and will make some concept of queue.
•
•Queue can be implemented as simple queue, circular queue, dequeue, priority
queue.
Queue in C
158. Applications of Queue:
Queue is used when things don’t have to be processed immediately, but
have to be processed in First In First Out order like Breadth First Search. This
property of Queue makes it also useful in following kind of scenarios.
1) When a resource is shared among multiple consumers. Examples include CPU
scheduling, Disk Scheduling.
2) When data is transferred asynchronously (data not necessarily received at
same rate as sent) between two processes. Examples include IO Buffers, pipes,
file IO, etc.
-- Following code describes simple queue implementation.
159. #include<stdio.h>
#define MAX 3
int queue[MAX],front=-1,rear=-1;
void push_element();
void pop_element();
void display_queue();
int num;
int main()
{
int op;
do
{
printf("nn 1.Insert an element");
printf("n 2.Delete an element");
printf("n 3.Display queue");
printf("n 4.Exit");
printf("n Enter your choice: ");
scanf("%d",&op);
164. Dequeues (double ended queues)
•A deque is a double-ended queue
•Insertions and deletions can occur at either end
•Implementation is similar to that for queues
•Deques are not heavily used
165. #include<stdio.h>
#define MAX 5
int front=-1,rear=-1;
int x;
int q[MAX];
void insert_rear(void);
void display(void);
void delete_rear(void);
void insert_front(void);
void delete_front(void);
166. int main()
{
int op;
int item;
do
{
printf("nn 1 -- INSERT at rear end");
printf("nn 2 -- INSERT at front end");
printf("nn 3 -- DELETE at rear end");
printf("nn 4 -- DELETE at front end");
printf("nn 5 -- display");
printf("nn 6 -- EXIT");
scanf("%d", &op);
167. switch(op)
{
case 1: insert_rear();
break;
case 2: insert_front();
break;
case 3: delete_rear();
break;
case 4: delete_front();
break;
case 5: display();
break;
case 6: return 0;
break;
default: printf("invalid numbern");
}}
while(op!=6);
}
168. void insert_rear(void)
{
int num;
printf("enter number to be insertedn");
scanf("%d",&num);
if(rear==MAX-1)
printf("n Queue is full...");
else if(rear==-1)
{
rear=0;
front=0;
q[rear]=num;
}
else
{
rear++;
q[rear]=num;
}}
169. void insert_front(void)
{
int no;
printf("n Enter value to insert:-");
scanf("%d",&no);
if(front<=0)
{
printf("n Cannot add value at front end");
return;
}
else
{
front--;
q[front]=no;
printf("q[%d]=%dn", front,q[front]);
printf("rear is %d, front is %dn",rear, front);
}}
173. Circular queues in C
Circular queue c is also implemented as same as simple queue, the main
difference is that in circular queue last element will again points to first element as
shown in figure.
174. #include<stdio.h>
#define MAX 3
int queue[MAX],front=-1,rear=-1;
void push_element();
void pop_element();
void display_queue();
int num;
int main()
{
int op;
do {
printf("nn 1.Insert an element");
printf("n 2.Delete an element");
printf("n 3.Display queue");
printf("n 4.Exit");
printf("n Enter your choice: ");
scanf("%d",&op);
176. void push_element()
{
if((front==0 && rear==MAX-1))
{
printf("nnQueue is full");
}
else
{
if((rear==-1)||(rear==MAX-1))
{
printf("nnenter number to be
inserted");
scanf("%d",&num);
rear=0;
front=0;
queue[rear]=num;
}
177. else
{
rear++;
if((queue[rear] != 0)&&(rear!=0))
{
printf("nnQueue is full");
goto x;
}
printf("nnenter number to be inserted");
scanf("%d",&num);
queue[rear]=num;
printf("nn num inserted is: queue[%d]=%d",rear,num);
}
x:
printf("nn rear is %d and front is %d",rear,front);
}
}
178. void pop_element()
{
if((front==-1)||(front==rear+1))
printf("nnqueue is emptyn");
else
{
num=queue[front];
queue[front]=0;
if(front==rear)
{ front=-1; rear=-1; }
else if(front==MAX-1)
front=0;
else
front++;
printf("nnnum popped is:queue[%d]=%dn",front,num);
}
printf("nn rear is %d and front is %d",rear,front);
}
179. void display_queue()
{
int i;
printf("nn rear is %d and front is %d",rear,front);
if((front==-1))//||(front==rear+1))
{
printf("nnqueue has no lements to displayn");
}
else
{
for(i=0;i<=2;i++)
printf("nnqueue[%d]=%d",i,queue[i]);
}
}
180. Priority queue
A priority queue is an abstract data type which is like a regular queue or stack
data structure, but where additionally each element has a "priority" associated with
it. In a priority queue, an element with high priority is served before an element with
low priority. If two elements have the same priority, they are served according to
their order in the queue.
181. /* C Prog to Implement Priority Queue to Add and Delete Elements (sorts in decreasing order) */
#include <stdio.h>
#include <stdlib.h>
#define MAX 5
void insert_by_priority(int);
void delete_by_priority(int);
void create();
void check(int);
void display_pqueue();
int pri_que[MAX];
int front, rear;
void main()
{
int n, ch;
printf("n1 - Insert an element into queue");
printf("n2 - Delete an element from queue");
printf("n3 - Display queue elements");
printf("n4 - Exit");
create();
182. void create()
{
front = rear = -1;
}
/* Function to insert value into priority queue */
void insert_by_priority(int data)
{
if (rear >= MAX - 1)
{
printf("nQueue overflow no more elements can be inserted");
return;
}
if ((front == -1) && (rear == -1))
{
front++;
rear++;
pri_que[rear] = data;
return;
}
else
check(data);
rear++;
}
183. /* Function to delete an element from queue */
void delete_by_priority(int data)
{
int i;
if ((front==-1) && (rear==-1))
{
printf("nQueue is empty no elements to delete");
return;
}
for (i = 0; i <= rear; i++)
{
if (data == pri_que[i])
{
for (; i < rear; i++)
{
pri_que[i] = pri_que[i + 1];
}
pri_que[i] = -99;
rear--;
if (rear == -1)
front = -1;
return;
}
}
printf("n%d not found in queue to delete", data);
}
184. Linked List
Like arrays, Linked List is a linear data structure. Unlike arrays, linked list elements are not stored at contiguous location; the elements are linked
using pointers.
Why Linked List?
Arrays can be used to store linear data of similar types, but arrays have following limitations.
1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is
equal to the upper limit irrespective of the usage.
2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing
elements have to shifted.
For example, in a system if we maintain a sorted list of IDs in an array id[].
id[] = [1000, 1010, 1050, 2000, 2040].
And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has
to be moved.
Advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
Drawbacks:
1) Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked
lists.
2) Extra memory space for a pointer is required with each element of the list.
185. Representation in C:
A linked list is represented by a pointer to the first node of the linked list. The first node is called head. If the linked list is empty, then value
of head is NULL.
Each node in a list consists of at least two parts:
1) data
2) pointer to the next node
In C, we can represent a node using structures. Below is an example of a linked list node with an integer data.
struct node
{
int data;
struct node *next;
};
186. Program to create liked list and print the data in linked list
#include<stdio.>
#include<conio.h>
#include<stdlib.h> or #include<alloc.h>
struct node
{
int data;
struct node *next;
} *start=NULL;
void create()
{
char ch;
do
{
struct node *new_node, *current;
new_node=(struct node *)malloc(sizeof(struct node));
printf(“enter the data :”);
scanf(“%d”,&new_node->data);
new_node->next=NULL;
if(start==NULL)
{
start=new_node;
current=new_node;
}
187. /* function to count length of linked list */
void count()
{
struct node *temp;
int length=0;
temp=start;
while(temp!=NULL)
{
length++;
temp=temp->next;
}
printf(“length of linked list : %d”, length);
}
/*function to traverse and search for data in linked list*/
int search (int num)
{
int flag=0;
struct node *temp;
temp=start;
while(temp!=NULL)
{
if (temp->data==num)
return (1); //found
temp=temp->next;
}
if(flag==0)
return (0);// not found
188. /*prog to delete first node from the linked list*/
void del_beg()
{
struct node *temp;
temp = start;
start = start->next;
free(temp);
printf("nThe Element deleted Successfully ");
}
-- write a prog to delete last node from a linked list
/*function to insert node at the middle of the linked list*/
void insert_mid()
{
int pos,i;
struct node *new_node,*current,*temp,*temp1;
new_node=(struct node *)malloc(sizeof(struct node));
printf("nEnter the data : ");
scanf("%d",&new_node->data);
new_node->next=NULL;
st :
printf("nEnter the position : ");
scanf("%d",&pos);
if(pos>=(length()+1))
{
printf("nError : pos > length ");
goto st;
}
if(start==NULL)
{
start=new_node;
current=new_node;
}
189. Circular linked list
Circular linked list is divided in too 2 catagories:
•Singly circular linked list
•Doubly circular linked list
Circular singly linked list
•Singly Linked List has a major drawback. From a specified node, it is not possible to reach any of the preceding nodes in the list. To overcome
the drawback, a small change is made to the SLL so that the next field of the last node is pointing to the first node rather than NULL. Such a
linked list is called a circular linked list.
•Because it is a circular linked list, it is possible to reach any node in the list from a particular node.
•There is no natural first node or last node because by virtue of the list is circular.
190. Tree in C
The binary tree is a fundamental data structure used in computer science. The binary tree is a useful data structure for rapidly storing
sorted data and rapidly retrieving stored data.
A binary tree is made of nodes, where each node contains a "left" pointer, a "right" pointer, and a data element. The "root" pointer points
to the topmost node in the tree. The left and right pointers recursively point to smaller "subtrees" on either side. A null pointer represents a
binary tree with no elements -- the empty tree. The formal recursive definition is: a binary tree is either empty (represented by a null pointer), or
is made of a single node, where the left and right pointers (recursive definition ahead) each point to a binary tree.
191. #include<stdio.h>
#include<stdlib.h>
typedef struct treeNode
{
int data;
struct treeNode *left;
struct treeNode *right;
}treeNode;
treeNode* FindMin(treeNode *node)
{
if(node==NULL)
{
return NULL;
}
if(node->left) /* Go to the left sub tree to find the min element */
return FindMin(node->left);
else
return node;
}
treeNode* FindMax(treeNode *node)
{
if(node==NULL)
{
return NULL;
}
if(node->right) /* Go to the left sub tree to find the min element */
FindMax(node->right);
else
return node;
}
192. treeNode * Find(treeNode *node, int data)
{
if(node==NULL)
{
/* Element is not found */
return NULL;
}
if(data > node->data)
{
/* Search in the right sub tree. */
return Find(node->right,data);
}
else if(data < node->data)
{
/* Search in the left sub tree. */
return Find(node->left,data);
}
else
{
/* Element Found */
return node;
}
}
void del_tree(treeNode * node)
{
if (node)
{
del_tree(node->left);
del_tree(node->right);
194. The Manual (terminal mode)
man This command brings up the online Unix
manual. Use it on each of the commands below.
For Example:
man pwd You will see the manual for the pwd command.
Accessing files in Folders (Directories) in terminal mode
pwd Shows what directory (folder) you are in.
In Linux, your home directory is /home/particle
· Let's suppose you have several data files (data1, data2 ... etc.) in a directory called muondata.
· Then suppose the directory muondata is an entry in your main home directory, /home/particle .
· If you are in your home directory (where terminals start) and type pwd, you will see /home/particle.
· If you were in the muondata directory, pwd would give you /home/particle/muondata instead
· The last slash after a directory name is optional.
As you can see, each slash (/) indicates another sub-directory.
cd Changes directories.
Examples of relative movement among directories:
cd muondata Moves down from your current directory
into the muondata sub-directory
195. cd .. Moves up one directory (yes, include the
two little dots)
You can also move directly into directories
cd /home/particle/muondata
Moves from ANY directory into the muondata
sub-directory of your home directory.
cd ~ Takes you back to your home directory
(/home/particle)
Making or Removing a Directory (terminal mode)
mkdir dirName Creates a directory with name dirName.
For Example:
mkdir temp Creates the directory temp.
rmdir dirName Removes a directory dirName.
For Example:
rmdir temp Removes the directory temp.
Looking at or Finding your Files (terminal mode)
ls Lists files.
If you add -al after ls it will give more details for each file. Such as, size, permissions, owners, dates etc.
196. ls al You'll see a huge list of files that you can't see with the 'ls' command alone and lots of details.
If you see such a long list of files that they scroll off the terminal screen, one way to solve the problem is to use:
ls -al |more Shows one screen of file names at a time.
less data1 Dumps the contents of the data1 file to your screen with a pause at each line so you don't miss any contents as they scroll.
You may move through the file using page up, page down, home and end keys. When done with less you use the q key to get back to the
main terminal.
whereis data1 Shows you the location of the data1 file.
Altering your Files
rm data1 Deletes the file data1 in the current directory.
rm -i muon* Removes all of your muon data files
(careful!! rm * will remove ALL your files)
The "-i" makes the computer prompt before removing each file. If you really want to work without a net, omit the "-i".
cp data1 newdata/ will copy the file data1 to the directory newdata (assuming it has already been created)
mv data1 newdata/ moves the file data1 to the folder newdata and deletes the old one.
Editor's Notes
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
&lt;number&gt;
which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single “heap area” is not required to fulfill the contract of malloc/realloc/free; they may also be implemented using mmap to reserve potentially non-contiguous regions of virtual memory into the process’ virtual address space). The Heap area is shared by all shared libraries and dynamically loaded modules in a process.